1
votes

I am using DSE 5.0.1 version. Earlier we used facet query to show search suggestions. For performance reasons , looking for other alternatives to get suggestions and found solr search suggester component. But I couldn't find examples where suggester component is used from a CQL query. Its possible right?Can anyone help me on this. Thanks in advance.

1

1 Answers

1
votes

Yes, it's possible and relatively easy - you just need to understand how to map XML that you want to put into generated solrconfig.xml into JSON that is used for configuration.

For example, we want to configure suggestor to suggest on the data from field title, and use additional weights from the rating field. As per Solr documentation the XML piece should look following way:

  <searchComponent class="solr.SuggestComponent" name="suggest">
    <lst name="suggester">
      <str name="name">titleSuggester</str>
      <str name="lookupImpl">AnalyzingInfixLookupFactory</str>
      <str name="dictionaryImpl">DocumentDictionaryFactory</str>
      <str name="suggestAnalyzerFieldType">TextField</str>
      <str name="field">title</str>
      <str name="weightField">rating</str>
      <str name="buildOnCommit">false</str>
      <str name="exactMatchFirst">true</str>
      <str name="contextField">country</str>
    </lst>
  </searchComponent>
  <requestHandler class="solr.SearchHandler" name="/suggest">
    <arr name="components">
      <str>suggest</str>
    </arr>
    <lst name="defaults">
      <str name="suggest">true</str>
      <str name="suggest.count">10</str>
    </lst>
  </requestHandler>

In CQL, it will be converted

ALTER SEARCH INDEX CONFIG ON table ADD 
  searchComponent[@name='suggest',@class='solr.SuggestComponent'] 
  WITH  $$ {"suggester":[{"name":"titleSuggester"}, 
   {"lookupImpl":"AnalyzingInfixLookupFactory"}, 
   {"dictionaryImpl":"DocumentDictionaryFactory"},
   {"suggestAnalyzerFieldType":"TextField"}, 
   {"field":"title"}, {"weightField":"rating"}, 
   {"buildOnCommit":"false"}, {"exactMatchFirst":"true"},
   {"contextField":"country"}]} $$;

ALTER SEARCH INDEX CONFIG ON table ADD 
  requestHandler[@name='/suggest',@class='solr.SearchHandler'] 
  WITH  $$ {"defaults":[{"suggest":"true"}, 
    {"suggest.count":"10"}],"components":["suggest"]} $$;

After that you need not to forget to execute:

RELOAD SEARCH INDEX ON table;

And your suggestor will work. In my example, the index for suggestor should be build explicitly because inventory doesn't change very often. This is done via HTTP call like this:

curl 'http://localhost:8983/solr/keyspace.table/suggest?suggest=true&suggest.dictionary=titleSuggester&suggest.q=Wat&suggest.cfq=US&wt=json&suggest.build=true&suggest.reload=true'

But you can control this by setting buildOnCommit to true. Or you can configure it to build suggestor index on start, etc. - see Solr's documentation.

Full example is here - this is an example of the e-commerce application.