You used the "replacement" rule format. You probably simply want the "equivalent" rule format:

car, mascot

And, you probably only want to do this at index time. This would mean that both "car" and "mascot" will be indexed at any position where either term occurs. And at query time you don't need a synonym filter since both terms are already in the index.

So, split your analyzer into an "index" analyzer and a "query" analyzer. The former would have the synonym filter, the latter would not.

-- Jack Krupansky

-----Original Message----- From: Andy Newby
Sent: Friday, August 03, 2012 12:08 PM
To: solr-user@lucene.apache.org
Subject: Can't get synonyms working

Hi,

I'm trying to work out why Synonyms won't work for my installation of Solr.
Its a basic install (just using the "example" set, and have tweaked the
fields to what I need).

The files are all in:  (schema.xml, synonyms.txt etc), but for some reason
its not working: /var/home/site/solr/example/solr/conf

For the text_ws field I have this set:

   <!-- A text field that only splits on whitespace for exact matching of
words -->
   <fieldType name="text_ws" class="solr.TextField"
positionIncrementGap="100">
     <analyzer>
       <tokenizer class="solr.WhitespaceTokenizerFactory"/>
     </analyzer>
     <analyzer type="query">
       <!--<tokenizer class="solr.StandardTokenizerFactory"/> -->
       <tokenizer class="solr.WhitespaceTokenizerFactory"/>
       <filter class="solr.StopFilterFactory" ignoreCase="true"
words="stopwords.txt" enablePositionIncrements="true" />
       <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt"
ignoreCase="true" expand="true"/>
       <filter class="solr.LowerCaseFilterFactory"/>
     </analyzer>
   </fieldType>

...and for the related fields I'm trying to search with the synonym file:

<field name="title"     type="text_ws"    indexed="true"  stored="true"
multiValued="false"  required="true" WhitespaceTokenizerFactory="true" />
 <field name="description"  type="text_ws"    indexed="true"
stored="true"  multiValued="false"  required="false"
WhitespaceTokenizerFactory="true"  />
 <field name="keywords"     type="text_ws"    indexed="true"
stored="true"  multiValued="false"  required="false"
WhitespaceTokenizerFactory="true"  />

In my synonynm file I have this example:

car => mascot
mascot => car

..and in Solr I actually have a result with the "description" of "<str
name="description">bird hawk mascot 002 (u65bsag)</str>"

...surely my setup should be showing that result?

I've been doing my head in over this - so any advice would be much
appreciated :)

TIA!
--
Andy Newby <a...@ultranerds.co.uk>

Reply via email to