【问题标题】:How to have Solr autocomplete on whole phrase - solr如何让 Solr 自动完成整个短语 - solr
【发布时间】:2015-10-14 18:04:18
【问题描述】:

我正在像谷歌一样创建建议。现在,当我写“do”时,solr 返回“dog”、“doll”,它只返回模式字段上的一个单词。 我想要的是如果它返回整个字段,例如“doggy blah blah”、“dog store”等,那就太好了。 这是我的 schema.xml

<field name = "companyDisplayName" type = "text_auto" multiValued="false" indexed = "true" stored = "false" />

和我的架构字段类型配置:

<fieldType name="text_auto" class="solr.TextField" positionIncrementGap="100" ><analyzer type="index">
    <tokenizer class="solr.KeywordTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.EdgeNGramFilterFactory" maxGramSize="30" minGramSize="1"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.KeywordTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

这是我的 solrconfig.xml

<searchComponent class="solr.SpellCheckComponent" name="suggest">
   <lst name="spellchecker">
      <str name="name">suggest</str>
      <str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
      <str name="lookupImpl">org.apache.solr.spelling.suggest.fst.AnalyzingInfixLookupFactory</str>
      <str name="buildOnCommit">true</str>
      <str name="suggestAnalyzerFieldType">text_auto</str>
      <str name="field">companyDisplayName</str>
   </lst>
</searchComponent>

<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggest">
<lst name="defaults">
    <str name="spellcheck">true</str>
    <str name="spellcheck.dictionary">suggest</str>
    <str name="spellcheck.onlyMorePopular">true</str>
    <str name="spellcheck.count">5</str>
    <str name="spellcheck.collate">false</str>
<str name="echoParams">explicit</str>
<str name="defType">edismax</str>
<str name="rows">10</str>
<str name="fl">companyDisplayName</str>
<str name="qf">companyDisplayName^30</str>
<str name="pf">companyDisplayName^50.0</str>
<str name="group">true</str>
<str name="group.field">companyDisplayName</str>
<str name="sort">score desc</str>
<str name="group.sort">score desc</str>
</lst>
<arr name="components">
    <str>suggest</str>
</arr>

和我的查询:

http://localhost:8983/solr/vw_search_company_with_buildings/suggest?spellcheck.q=hunn

【问题讨论】:

    标签: xml solr


    【解决方案1】:

    您需要进行多项更改才能让您的建议者开始工作。

    stored=true 用于您要在建议中使用的文件。我建议您使用copyField 标签将该字段复制到另一个字段中。您不需要为复制的字段编制索引。您可以替换 schema.xml 中的 text_general 定义。它与默认相同,但版本更简单。

    <field name = "suggest_field" type = "text_general" multiValued="false" indexed = "false" stored = "true" />
    
    <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
        <analyzer>
            <tokenizer class="solr.StandardTokenizerFactory"/>
            <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
            <filter class="solr.LowerCaseFilterFactory"/>
        </analyzer>
    </fieldType>
    

    现在为建议者searchComponentrequestHandler 使用以下配置。此配置使用solr.SuggestComponent 而不是solr.SpellCheckComponent。对于AnalyzingInfixLookupFactory,默认高亮是true,这里是false。我添加了&lt;str name="dictionaryImpl"&gt;DocumentDictionaryFactory&lt;/str&gt; 以获取建议器中的完整属性值。

    <searchComponent name="suggest" class="solr.SuggestComponent">
    <lst name="suggester">
        <str name="name">suggest</str>
        <str name="lookupImpl">AnalyzingInfixLookupFactory</str>
        <str name="dictionaryImpl">DocumentDictionaryFactory</str>
        <str name="field">suggest_field</str>
        <str name="suggestAnalyzerFieldType">text_general</str>
        <str name="buildOnCommit">true</str>
        <str name="highlight">false</str>
    </lst>
    </searchComponent>
    
    
    <requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
    <lst name="defaults">
        <str name="suggest">true</str>
        <str name="suggest.dictionary">suggest</str>
        <str name="suggest.count">10</str>
        <str name="suggest.onlyMorePopular">true</str>
        <str name="suggest.count">5</str>
        <str name="suggest.collate">false</str>
        <str name="echoParams">explicit</str>
        <str name="defType">edismax</str>
        <str name="rows">10</str>
        <str name="fl">suggest_field</str>
        <str name="qf">suggest_field^30</str>
        <str name="pf">suggest_field^50.0</str>
        <str name="group">true</str>
        <str name="group.field">suggest_field</str>
        <str name="sort">score desc</str>
        <str name="group.sort">score desc</str>
    </lst>
    <arr name="components">
        <str>suggest</str>
    </arr>
    </requestHandler>
    

    使用以下命令提出建议请求。这在 url 中包含suggest.build=true,这意味着它会在您每次发出请求时构建字典。您可以将其删除以用于生产目的。

    http://localhost:8983/solr/vw_search_company_with_buildings/suggest?suggest.build=true&suggest.q=do
    

    PS : AnalyzingInfixLookupFactory 存在问题,它会在您第二次重新加载建议字典目录时锁定它。您可以使用indexPath 解决问题。

    这里是reference link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-11
      • 1970-01-01
      • 2013-09-14
      相关资源
      最近更新 更多