我有一个属性" bodyType"它有多个值,如轿车,SUV,轿跑车等。如果我想搜索轿车我应用facetFilters像[@" bodytype:sedan"]它工作正常,但如果我想看到两个轿车然后我做[@" bodyType:sedan",@" bodyType:suv"]并返回零结果。我正在使用目标c ios sdk。
提前致谢
答案 0 :(得分:9)
使用facetFilters
时,顶级过滤器是隐式结合的(即与AND
运算符组合)。这就是您没有看到结果的原因:两个结果集的交集都是空的。
要提供析取过滤器(OR
运算符),请使用嵌套数组,如documentation中所述:
[["bodyType:sedan", "bodyType:suv"]]
将filters
与bodyType:sedan OR bodyType:suv
一起使用也可以。
答案 1 :(得分:1)
快速查看文档,听起来filters
属性可以满足您的需求:
/**
* Filter the query with numeric, facet or/and tag filters. The syntax is a SQL like syntax, you can use the OR and AND keywords.
* The syntax for the underlying numeric, facet and tag filters is the same than in the other filters:
* available=1 AND (category:Book OR NOT category:Ebook) AND public
* date: 1441745506 TO 1441755506 AND inStock > 0 AND author:"John Doe"
* The list of keywords is:
* OR: create a disjunctive filter between two filters.
* AND: create a conjunctive filter between two filters.
* TO: used to specify a range for a numeric filter.
* NOT: used to negate a filter. The syntax with the ‘-‘ isn’t allowed.
*/
@property (nonatomic) NSString *filters;
举个例子:
NSString *filterString = @"bodyType:sedan OR bodyType:suv";
ASRemoteIndex *indexForClient = [self getIndex:BASIC_INDEX_NAME];
ASQuery *newQuery = [[ASQuery alloc] init];
[newQuery setHitsPerPage:[HITS_PER_PAGE integerValue]];
[newQuery setPage:pageNumber];
if (filtersString) {
[newQuery setFilters:filtersString];
}
if (tagFilters) {
[newQuery setFullTextQuery:tagFilters];
}
if (filterString.length) {
[newQuery setFilters:filterString];
}