简体   繁体   English

如何限制Solr在3个字母后建议记录

[英]How to restrict solr to suggest records after 3 letters

  1. List item 项目清单
  2. Solr version - 6.6.0 Solr版本-6.6.0

I am adding a new field in the documents say "autocomplete" and copying data from other relevant keys. 我在文档中添加了一个新字段,说“自动完成”,并从其他相关密钥中复制数据。

Changes in schema.xml schema.xml更改

<field name="autocomplete" type="text_general" indexed="true" stored="true"
multiValued="true" />

<copyField source="a" dest="autocomplete"/>
<copyField source="b" dest="autocomplete"/>
<copyField source="c" dest="autocomplete"/>
<copyField source="d" dest="autocomplete"/>

Changes in suggester of solrconfig.xml solrconfig.xml建议程序中的更改

  <searchComponent name="suggest" class="solr.SuggestComponent">
    <lst name="suggester">
      <str name="name">infixSuggester</str>
      <str name="lookupImpl">AnalyzingInfixLookupFactory</str>  
      <str name="dictionaryImpl">DocumentDictionaryFactory</str>
      <str name="field">autocomplete</str>
       <str name="contextField">type</str>
      <str name="suggestAnalyzerFieldType">text_general</str>
      <str name="buildOnStartup">false</str>
    </lst>
  </searchComponent>

I can query over it and use context filter as well. 我可以查询它,也可以使用上下文过滤器。

Can I restrict it to show records only after 3 letters input? 我可以限制它仅在输入3个字母后才显示记录吗?

Usually this is the kind of change that would be client side. 通常,这是客户端的一种更改。 You can send an API call just when you reach your configured amount of characters. 只要达到配置的字符数,就可以发送API调用。

Solr side : Solr侧:

Unfortunately, using the analysing infix lookup strategy, it is not possible to change the min chars for the possible suggestions. 不幸的是,使用分析中缀查找策略,不可能为可能的建议更改最小字符。 This is because, when creating the possible suggestions in the auxiliary index, the minimum ngram is hardcoded to be 1 : 这是因为,当在辅助索引中创建可能的建议时,最小ngram被硬编码为1:

org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java:364
TokenFilter filter = new EdgeNGramTokenFilter(components.getTokenStream(), 1, minPrefixChars);

Given N your desired amount of characters: If you really want to do that Solr side, then you can do that explicitly configuring an autocompletion field ( analysed with an edgeNgram token filter with a min value of N for the ngram). 给定N您所需的字符数:如果您确实想在Solr方面进行操作,则可以这样做,以显式配置自动完成字段(使用edgeNgram令牌过滤器进行分析,ngram的最小值为N)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM