Autocomplete for phrases solrj

406 views Asked by At

I am trying to add autocomplete feature for the phrase queries. Have the following configuration - in schema.xml file

<field name="textSpell" type="spell" indexed="true" stored="true"
        multiValued="true" termVectors="true" termPositions="true"
        termOffsets="true" />
<field name="suggest_phrase" type="suggest_phrase" indexed="true"
        stored="false" multivalued="false"/>

in solrconfig.xml

<searchComponent name="suggest" class="solr.SuggestComponent">
    <lst name="suggester">
      <str name="name">default</str>
      <str name="classname">solr.IndexBasedSpellChecker</str>      
      <str name="lookupImpl">org.apache.solr.spelling.suggest.fst.AnalyzingLookupFactory</str>      <!-- org.apache.solr.spelling.suggest.fst -->
      <str name="dictionaryImpl">DocumentDictionaryFactory</str>     <!-- org.apache.solr.spelling.suggest.HighFrequencyDictionaryFactory --> 
      <str name="field">textSpell</str>
      <float name="thresholdTokenFrequency">.0001</float>

     <!-- <str name="weightField">price</str>-->
      <str name="suggestAnalyzerFieldType">string</str>
      <str name="buildOnCommit">true</str>
      <!--<str name="buildOnOptimize">true</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>
    </lst>
    <arr name="components">
      <str>suggest</str>
    </arr>
  </requestHandler>

  <!-- Suggest Phrase -->
    <searchComponent name="suggest_phrase" class="solr.SpellCheckComponent">
        <lst name="spellchecker">
            <str name="name">suggest_phrase</str>
            <str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
            <str name="lookupImpl">org.apache.solr.spelling.suggest.fst.FSTLookup</str>
            <str name="field">suggest_phrase</str>
            <str name="buildOnCommit">true</str>
        </lst>
    </searchComponent>

    <requestHandler class="solr.SearchHandler"
        name="/suggest_phrase" startup="lazy">
        <lst name="defaults">
            <str name="spellcheck">true</str>
            <str name="spellcheck.dictionary">suggest_phrase</str>
            <str name="spellcheck.onlyMorePopular">true</str>
            <str name="spellcheck.count">10</str>
            <str name="spellcheck.collate">false</str>
        </lst>
        <arr name="components">
            <str>suggest_phrase</str>
        </arr>
    </requestHandler>

Also I am setting the following things - for the query to solr using solrj

SolrQuery suggestQuery = new SolrQuery();
suggestQuery.setParam(CommonParams.QT, "/terms");
suggestQuery.setParam(TermsParams.TERMS, true);
suggestQuery.setParam(TermsParams.TERMS_LIMIT, "5");
suggestQuery.setParam(TermsParams.TERMS_FIELD,"content");
suggestQuery.setParam(TermsParams.TERMS_LOWER, query);
suggestQuery.setParam(TermsParams.TERMS_PREFIX_STR, query);
suggestQuery.setParam("spellCheck", "true");
suggestQuery.setParam("spellcheck.q", query);

However, it doesn't yield results for phrase queries works only on single terms. Any suggestions. I am using Solr4.10.2

1

There are 1 answers

0
Josh Edwards On

You are using two fieldTypes: "spell" and "suggest_phrase." How are they defined? The first thing I would check is whether or not you are using a WhitespaceTokenizerFactory on them - in which case, it wouldn't work over a phrase because the space in a phrase would terminate the token.