Algolia 切面属性多个值
Algolia facet attribute multiple values
我有一个属性 "bodyType",它有多个值,如轿车、suv、coupe 等。如果我想搜索轿车,我应用 [@"bodytype:sedan"] 之类的 facetFilters 并且它有效很好,但如果我想同时看到轿车和 suv,那么我会执行 [@"bodyType:sedan"、@"bodyType:suv"] 并且结果 returns 为零。我正在使用 objective c ios sdk.
提前致谢
快速查看了文档,听起来 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];
}
使用 facetFilters
时,顶级过滤器是隐式连接的(即与 AND
运算符组合)。这就是您看不到任何结果的原因:两个结果集的交集为空。
要提供析取过滤器(OR
运算符),请使用嵌套数组,如 documentation:
中所述
[["bodyType:sedan", "bodyType:suv"]]
将 filters
与 bodyType:sedan OR bodyType:suv
一起使用也可以。
我有一个属性 "bodyType",它有多个值,如轿车、suv、coupe 等。如果我想搜索轿车,我应用 [@"bodytype:sedan"] 之类的 facetFilters 并且它有效很好,但如果我想同时看到轿车和 suv,那么我会执行 [@"bodyType:sedan"、@"bodyType:suv"] 并且结果 returns 为零。我正在使用 objective c ios sdk.
提前致谢
快速查看了文档,听起来 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];
}
使用 facetFilters
时,顶级过滤器是隐式连接的(即与 AND
运算符组合)。这就是您看不到任何结果的原因:两个结果集的交集为空。
要提供析取过滤器(OR
运算符),请使用嵌套数组,如 documentation:
[["bodyType:sedan", "bodyType:suv"]]
将 filters
与 bodyType:sedan OR bodyType:suv
一起使用也可以。