【问题标题】:Algolia facet attribute multiple valuesAlgolia 方面属性多个值
【发布时间】:2017-03-22 22:40:15
【问题描述】:

我有一个属性“bodyType”,它有多个值,如轿车、suv、双门轿车等。如果我想搜索轿车,我应用 facetFilters,如 [@"bodytype:sedan"],它工作正常,但如果我想同时查看轿车和 suv,然后我执行 [@"bodyType:sedan", @"bodyType:suv"] 并返回零结果。我正在使用objective c ios sdk。

提前致谢

【问题讨论】:

  • 显示您用于搜索的其余代码。
  • 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 ([facetFilterArray count]) { [newQuery setFacetFilters:facetFilterArray]; }
  • 请使用格式正确的代码编辑您的初始问题:)

标签: objective-c facet algolia


【解决方案1】:

使用facetFilters 时,顶级过滤器是隐式连接的(即与AND 运算符结合使用)。这就是您看不到结果的原因:两个结果集的交集都是空的。

要提供析取过滤器(OR 运算符),请使用嵌套数组,如 documentation 中所述:

[["bodyType:sedan", "bodyType:suv"]]

filtersbodyType:sedan OR bodyType:suv 一起使用也可以。

【讨论】:

    【解决方案2】:

    快速浏览一下文档,听起来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 来做到这一点。我相信我们可以检查同一属性的多个值。我们不能吗?
    • 我认为问题在于 facetFilters 固有地使用 AND 逻辑。即您正在过滤一个同时具有“suv”和“轿车”车身类型的对象,因此结果为零。据我所知,没有办法改变这一点。 filters 只是给你更多的移动空间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-12
    • 2018-06-19
    • 1970-01-01
    相关资源
    最近更新 更多