2

I am trying to implement auto-complete feature for search using Solr's suggester component. I want to give suggestions across multiple fields. I have 2 fields taxonomy and tag which I want to provide in suggestions. Eg if the search query is neck then it should return:

necklace
neckalce sets
pearl necklace
diamond necklace
pearl necklace sets
diamond necklace sets

where necklace is a taxonomy and pearl and diamond are tags.

Following is my schema.xml:

<field name="suggestion" type="text_auto" indexed="true" stored="false" multiValued="false" />

<copyField source="taxonomy_name" dest="suggestion"/>
<copyField source="tag" dest="suggestion">

<fieldType name="text_auto" class="solr.TextField">
  <analyzer>
   <tokenizer class="solr.KeywordTokenizerFactory"/>
   <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

and my solrconfig.xml:

<searchComponent class="solr.SpellCheckComponent" name="suggest">
<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.tst.TSTLookup</str>
  <str name="field">suggestion</str>  <!-- the indexed field to derive suggestions from -->
  <float name="threshold">0.005</float>
  <str name="buildOnCommit">true</str>
</lst>
</searchComponent>


<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggest">
 <lst name="defaults">
   <str name="spellcheck">true</str>
   <str name="spellcheck.dictionary">suggest</str>
   <str name="spellcheck.onlyMorePopular">true</str>
   <str name="spellcheck.count">5</str>
   <str name="spellcheck.collate">true</str>
 </lst>
 <arr name="components">
   <str>suggest</str>
 </arr>
</requestHandler>

But this returns:

necklace
necklace sets

How can I fix this. I also tried using :

<fieldType name="text_auto" class="solr.TextField"> 
  <analyzer> 
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
    <filter class="solr.ShingleFilterFactory" maxShingleSize="2" outputUnigrams="false"/>
    <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
  </analyzer> 
</fieldType> 

But this returns only necklace sets.

Phuc Thai
  • 718
  • 7
  • 17
nish
  • 6,952
  • 18
  • 74
  • 128

3 Answers3

1

Autocomplete in SolR only works if the query is the first word.

If the query is "neck" the autocomplete should return terms which begins with "neck". It cannot return "pearl necklace" because "pearl" is before your query.

Check this link for a possible solution : http://www.cominvent.com/2012/01/25/super-flexible-autocomplete-with-solr/

  • makes sense. So, could I return something like `necklace pearl`, which I can later flip around. – nish Nov 27 '13 at 12:17
  • You should flip `necklace pearl` but you shouldn't flip `necklace sets` so you will have to make the difference between these two cases (not so easy) – Jean-Marc Desprez Nov 27 '13 at 12:26
1

Add this to the <searchHandler>

<str name="lookupImpl">AnalyzingInfixLookupFactory</str>

This will enable you to search pearl necklace as well, as it recognizes the text in the middle of a word/phrase/field.

Anusha
  • 647
  • 11
  • 29
0

Did you try ?

<fieldType name="text_auto" class="solr.TextField"
positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.UAX29URLEmailTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true"
words="stopwords.txt" enablePositionIncrements="true" />
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ASCIIFoldingFilterFactory"/>
<filter class="solr.EnglishPossessiveFilterFactory"/>
</analyzer>
</fieldType>
Arun
  • 1,777
  • 10
  • 11
  • I tried this, but I'm getting only `necklace` and `necklaces`. Do I need to make changes only in schema.xml or do I need to make the same changes in scema.all.xml as well? – nish Nov 27 '13 at 05:52