gpt4 book ai didi

当存在动态字段时,Solr 突出显示不适用于多个字段 hl.fl

转载 作者:行者123 更新时间:2023-12-04 22:04:02 24 4
gpt4 key购买 nike

我有一个动态文本字段 bar_*在我的索引中,并希望 Solr 返回该字段的突出显示。所以我运行的是:

q=gold&hl=true&hl.fl=bar_*

它按预期工作,但以防万一我向 hl.fl 添加更多字段它停止工作。例如。
q=gold&hl=true&hl.fl=bar_*,foo

笔记:
  • bar_*foo字段在索引/架构中,这里没有错误。
  • 只是将请求重写为 q=gold&hl=true&hl.fl=bar_*&hl.fl=fooq=gold&hl=true&hl.fl=bar_* foo没有帮助。
  • 我在 Solr JIRA 中没有发现关于该主题的任何错误。

  • 有谁知道如何咬这个。我看到的可能的解决方法是:
  • 使用 hl.fl=* .但这对性能不利。
  • 为我的动态字段明确指定所有可能的字段名称。但我一点也不喜欢那样。
  • 最佳答案

    我不知道使用的是什么版本,但似乎这是以前 Solr 版本的错误,我可以确认在 Solr 7.3 中它按预期工作。

    curl -X GET \
    'http://localhost:8983/solr/test/select?q=x_ggg:Test1%20OR%20bar_x:Test2&hl=true&hl.fl=%2A_ggg,foo,bar_%2A' \
    -H 'cache-control: no-cache'

    更正确的做法是: hl.fl=bar_*,foo,*_ggg (使用 , 或空格作为分隔符)。

    当您从 hl.fl 中删除星号时,这有助于避免长时间的调试。参数和按字段突出显示停止工作,因为该字段不再作为正则表达式处理。

    以下是 Solr 7.3 源代码中的点,我们可以在其中跟踪此行为:
  • Solr 调用 org.apache.solr.highlight.SolrHighlighter#getHighlightFields
  • 处理字段前,值除以 ,或空间:org.apache.solr.util.SolrPluginUtils#split
  •   private final static Pattern splitList=Pattern.compile(",| ");

    /** Split a value that may contain a comma, space of bar separated list. */
    public static String[] split(String value){
    return splitList.split(value.trim(), 0);
    }
  • 拆分结果转到方法 org.apache.solr.highlight.SolrHighlighter#expandWildcardsInHighlightFields .

  • 在文档中还提到了预期契约(Contract) https://lucene.apache.org/solr/guide/7_3/highlighting.html

    hl.fl Specifies a list of fields to highlight. Accepts a comma- or space-delimited list of fields for which Solr should generate highlighted snippets.

    A wildcard of * (asterisk) can be used to match field globs, such as text_* or even * to highlight on all fields where highlighting is possible. When using *, consider adding hl.requireFieldMatch=true.

    When not defined, the defaults defined for the df query parameter will be used.

    关于当存在动态字段时,Solr 突出显示不适用于多个字段 hl.fl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47690813/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com