Search code examples
solrsearch-suggestion

Solr suggester returns many times the same results, with empty weights


I have the following problem with Solr's suggester: it's returning many times the same value, and all weights are zero. I would hope it would return each value only one time, with weights according to the frequency.

This is my config:

  <searchComponent name="suggest" class="solr.SuggestComponent">
    <lst name="suggester">
      <str name="name">infixSuggester</str>
      <str name="lookupImpl">AnalyzingInfixLookupFactory</str>
      <str name="indexPath">infix_suggestions</str>
      <str name="dictionaryImpl">DocumentDictionaryFactory</str>
      <str name="field">title_suggest</str>
      <str name="suggestAnalyzerFieldType">phrase_suggest</str>
      <str name="buildOnStartup">true</str>
      <str name="buildOnCommit">true</str>
    </lst>
  </searchComponent>

  <requestHandler name="/suggest" class="solr.SearchHandler">
    <lst name="defaults">
      <str name="suggest.dictionary">infixSuggester</str>
      <str name="suggest.onlyMorePopular">true</str>
      <str name="suggest">true</str>
      <str name="suggest.count">500</str>
      <str name="suggest.collate">true</str>
    </lst>
    <arr name="components">
      <str>suggest</str>
    </arr>
  </requestHandler>

when I call for example suggest?q=test, I get something like:

"suggestions":[{
    "term":"This is a test suggestion",
    "weight":0,
    "payload":""},
  {
    "term":"This is a test suggestion",
    "weight":0,
    "payload":""},
  {
    "term":"Another test example",
    "weight":0,
    "payload":""}]

So I have to do processing in my client to get only the most popular completions. I would hope to have something closer to:

"suggestions":[{
    "term":"This is a test suggestion",
    "weight":2,
    "payload":""},
  {
    "term":"Another test example",
    "weight":1,
    "payload":""}]

Is that possible at all?

Thanks!

Yann


Solution

  • You could use BlendedInfixLookupFactory suggester instead, its an advanced version of AnalyzingInfixLookupFactory, providing you with other features and removes the duplicates... Win-Win!