【问题标题】:Solr - {!ex} on a facet querySolr - {!ex} 在方面查询上
【发布时间】:2014-01-07 23:04:44
【问题描述】:

背景

我正在尝试将 2 个单独工作的功能组合起来,但无法将它们一起工作。

*1) 正如solr wiki 中所述,我可以标记一个特定的 fq,然后在我的 facet.field 中排除它。即使选择一个值,这也会使我的构面计数保持不变,如下所示:

fq={!tag=pt}price:100&facet=true&facet.field={!ex=pt}price

*2) 我想使用 facet.query 如下:

facet=true&facet.query=price:[0 TO 100]&facet.query=price:[100 TO *]

所以我想结合*1和*2,这是我尝试的:

fq={!tag=pt}price:[0 to 100]&facet=true&facet.query={!ex=pt}price:[0 TO 100]&facet.query={!ex=pt}price:[100 TO *]

实际发生的情况是我收到了 Solr 的回复:

<lst name="facet_queries">
    <int name="{!ex=pt}price:[0 TO 100]">8</int>
    <int name="{!ex=pt}price:[100 TO *]">19</int>
</lst>

我的问题是:

为什么名称中有 {!ex=pt} 部分?这搞乱了我的一些逻辑。 也许我误用了它,如果是这样,那么正确的方法是什么?

更多信息

我的期望是这样的:(与运行 *2 而没有 *1 的情况相同)

<lst name="facet_queries">
    <int name="price:[0 TO 100]">8</int>
    <int name="price:[100 TO *]">19</int>
</lst>

这是有道理的,因为如果我正在运行 *1,这就是我在 facet_fields 中收到的内容:

<lst name="facet_fields">
    <lst name="price">
        <int name="80">8</int>
        <int name="150">19</int>
    </lst>
</lst>

它没有说 name="{!ex=pt}price"

【问题讨论】:

    标签: solr lucene


    【解决方案1】:

    我认为这是因为:

    • *1 示例使用 facet.field,其命名方式应与其使用的字段相同(没有任何排除信息)。
    • *2 示例使用 facet.query 应该代表 query(查询中使用的所有可能信息......显示查询的一部分是没有意义的,例如没有排除部分)

    无论如何,如果需要命名使用排除功能的特定方面,则可以通过以下方式完成(使用 key 参数):

    facet.field={!ex=pt key=good_name_for_a_facet}price

    facet.query 的效果相同...例如,如果您确实想要隐藏 ex 部分:

    facet.query={!ex=pt key=$queryOne}price:[0 TO 100]

    其中 queryOne 是作为 queryOne=price:[0 TO 100] 传递给 solr 的原始参数的一部分

    所以最终的查询将如下所示:

    fq={!tag=pt}price:[0 TO 100]&facet=true&facet.query={!ex=pt key=$queryOne}price:[0 TO 100]&facet.query={!ex=pt key=$queryTwo}price:[100 TO *]&queryOne=price:[0 TO 100]&queryTwo=price:[100 TO *]
    

    附:我使用了外部参数作为键,因为这样 - 不需要手动转义特殊字符。

    【讨论】:

    • 工作+我现在明白背后的原因了,谢谢:)
    【解决方案2】:

    我遇到了这个问题,我通过向 {!ex} 参数添加本地参数键来解决它。所以对于你的例子,我会这样做:

    fq={!tag=pt}price:[0 to 100]&facet=true&facet.query={!ex=pt key="0 TO 100"}price:[0 TO 100 ]&facet.query={!ex=pt key="100 TO *"}价格:[100 TO *]

    原因是 QueryFacet 与 FieldFacet 的处理方式不同(facet.field vs facet.query)。 Solr 仅删除本地参数,即 FieldFacet 键中的 {!ex ...}。我实际上将其追踪到了代码,正如您在下面链接的 FacetComponent.java (v 4.6) 的第 680 行中看到的那样:

    http://svn.apache.org/viewvc/lucene/dev/tags/lucene_solr_4_6_0/solr/core/src/java/org/apache/solr/handler/component/FacetComponent.java?view=markup

    我没有进一步关注这个问题,因为我的用例无论如何都需要一个“漂亮”的键:)

    【讨论】:

    • 谢谢!我选择了@rchukh 的答案,因为它有更多信息
    【解决方案3】:

    我是这样解决的:

    for (int i = 0; i < facetQueries.size(); i++) {
        String value = facetQueries.get(i);
        query.addFacetQuery(String.format("{!ex=%s key=$fQValue_%s}%s", value, i, value));
        query.add(String.format("fQValue_%s", i), value);
    }
    

    【讨论】:

      猜你喜欢
      • 2012-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-13
      • 2014-01-30
      • 1970-01-01
      • 2012-07-29
      • 1970-01-01
      相关资源
      最近更新 更多