1

I am developing a web application, and am using Solr as search engine. I would like to add autocomplete functionality. To do this, I have added the Suggester component, and configured a separate field for it. This works ok.

The problem is that Suggester returns the whole value of the field. For example, if the name of an article is "A newsworthy item" and I search for "new", it will return the whole "A newsworthy item", where I would like it to just return "newsworthy". In other words, return the individual word tokens.

The schema looks like this:

<fieldType name="text_autocomplete" class="solr.TextField" positionIncrementGap="100">
  <analyzer>
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

<field name="term" type="text_autocomplete" indexed="true" stored="true" multiValued="false" />
<field name="weight" type="float" indexed="true" stored="true" />

<copyField source="name" dest="term"/>

The values are copied into the "term" field. The Solr config:

<!-- Search component -->
<searchComponent name="suggest" class="solr.SuggestComponent">
  <lst name="suggester">
    <str name="name">suggester</str>
    <str name="lookupImpl">AnalyzingLookupFactory</str>
    <str name="dictionaryImpl">DocumentDictionaryFactory</str>
    <str name="field">term</str>
    <str name="weightField">weight</str>
    <str name="suggestAnalyzerFieldType">text_autocomplete</str>
    <str name="buildOnStartup">false</str>
  </lst>
</searchComponent>

<!-- Search handler -->
<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
  <lst name="defaults">
    <str name="suggest">true</str>
    <str name="suggest.count">10</str>
    <str name="suggest.dictionary">suggester</str>
    <str name="suggest.build">true</str>
  </lst>
  <arr name="components">
    <str>suggest</str>
  </arr>
</requestHandler>

Can anyone suggest a schema and/or configuration that will make the Suggester return a single word?

4

1 回答 1

1

尝试使用 solr.SpellCheckComponent 而不是 solr.SuggestComponent。由于 SuggestComponent 旨在建议完整的短语。您可以在此处查看 solr.SpellCheckComponent 的详细信息。

http://wiki.apache.org/solr/SpellCheckComponent

为了您快速参考,您可以尝试使用它。

<searchComponent name="suggest" class="solr.SpellCheckComponent">
<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.FSTLookupFactory</str>
    <str name="distanceMeasure">org.apache.lucene.search.spell.JaroWinklerDistance</str>
    <str name="field">term</str>
    <str name="accuracy">0.7</str>
    <float name="thresholdTokenFrequency">.0001</float>

</lst>
</searchComponent>
于 2016-09-20T12:24:43.543 回答