Search code examples
solrlucenespell-checkingautosuggestsearch-suggestion

Couldn't get data in suggester even when storeDir getting created by FileDictionaryFactory


This is a follow up question of this question. I have a list of cities onto which I want to implement spell-checker. I have the priorities/weights of these cities with me. I tried implementing a solrsuggester with a FileDictionaryFactory as a base with the following format:

<city-name>  <TAB>  <weight>  <TAB>  <other parameters like citycode,country>

I am passing other attributes like citycode, country etc as pipe separated payload string.

Here's my solrconfig

<searchComponent name="suggest" class="solr.SuggestComponent">
    <lst name="suggester">
      <str name="name">mySuggester</str>
      <str name="lookupImpl">FuzzyLookupFactory</str>      
      <str name="dictionaryImpl">FileDictionaryFactory</str>     
      <str name="field">name</str>
      <str name="weightField">searchscore</str>
      <str name="suggestAnalyzerFieldType">string</str>
      <str name="buildOnStartup">false</str>
      <str name="sourceLocation">spellings.txt</str>
      <str name="storeDir">autosuggest_dict</str>
    </lst>
  </searchComponent>

  <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">mySuggester</str>
    </lst>
    <arr name="components">
      <str>suggest</str>
    </arr>
  </requestHandler>

and my schema

<field name="name" type="string" indexed="true" stored="true" multiValued="false" />
<field name="countrycode" type="string" indexed="true" stored="true" multiValued="false" />
<field name="latlng" type="location" indexed="true" stored="true" multiValued="false" />
<field name="searchfield" type="text_ngram" indexed="true" stored="false" multiValued="true" omitNorms="true"  omitTermFreqAndPositions="true" />

<uniqueKey>id</uniqueKey>
<defaultSearchField>searchfield</defaultSearchField>
<solrQueryParser defaultOperator="OR"/>
<copyField source="name" dest="searchfield"/>

Now the problem I am facing is I am getting 0 results for each and every search query. Even though I can see the storeDir getting created and it has a bin file with data looks like my payload data.

This is the url format I am using

/suggest?suggest=true&suggest.dictionary=mySuggester&wt=json&suggest.q=cologne

So, I have the following questions:

  1. What does the creation of storeDir signify ? Is it indexed successfully
  2. If yes, then what's wrong with my query ? If no, Am I missing something here(indexPath ???).
  3. Is it the right way to supply search parameters on payload field ? If no, is there any other way ?

Solution

  • I was using searchfield as defaultSearchField in schema, but had configured name as suggest field. The moment I changed field to searchfield and suggestAnalyzerFieldType to text_ngram, it started working.

    Here is the working solrconfig:

    <searchComponent name="suggest" class="solr.SuggestComponent">
            <lst name="suggester">
                  <str name="name">suggestions</str>
                  <str name="lookupImpl">FuzzyLookupFactory</str>
                  <str name="dictionaryImpl">FileDictionaryFactory</str>
                  <str name="field">searchfield</str>
                  <str name="weightField">searchscore</str>
                  <str name="suggestAnalyzerFieldType">text_ngram</str>
                  <str name="buildOnStartup">false</str>
                  <str name="buildOnCommit">false</str>
                  <str name="sourceLocation">spellings.txt</str>
                  <str name="storeDir">autosuggest_dict</str>
            </lst>
     </searchComponent>
    
      <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">suggestions</str>
                    <str name="suggest.dictionary">results</str>
            </lst>
            <arr name="components">
                    <str>suggest</str>
            </arr>
      </requestHandler>