Reputation: 3219
I'm trying to execute synonym filtering at query time so that if I search for X, results for Y also show up.
I go to where Solr is being run, edit the .txt file and add X, Y on a new line.
This does not work. I check the schema and I see:
<analyzer type="query">
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true" />
What am I missing?
EDIT Assessing configuration files
tomcat6/Catalina/localhost seems to point to the correct location
<Context docBase="/data/solr/solr.war" debug="0" privileged="true" allowLinking="true" crossContext="true">
<Environment name="solr/home" type="java.lang.String" value="/data/solr" override="true" />
</Context>
Also, in the Solr admin I see this. What does cwd mean?
cwd=/usr/share/tomcat6 SolrHome=/data/solr/
Upvotes: 5
Views: 8596
Reputation: 18166
The answer from @Walter Underwood is good, but incomplete.
Whether you use the SynonymFilterFactory at index or query time depends on your default operator.
So, let's say we have a synonym file with this entry:
5,five
If your default operator is OR
(which is the default default operator), then you should set up your synonyms on the query filter. This way a query for "5" will be passed to the backend as a query for "5" OR "five", say, and the backend would respond appropriately. At the same time, you can make changes to your synonym file without reindexing, and your index is smaller since it doesn't have to have so many tokens.
However, if you change the default operator to AND
, you should set up your synonyms on the index filter instead. If you don't, a query for "5" would go to the backend as "5" AND "five", and it would not match the documents that it's expected to. This, alas, makes the index bigger, and also means new synonyms require complete reindexes.
Note: The documentation for this is currently wrong, leaving out all these details.
Upvotes: 1
Reputation: 1221
Use the SynonymFilterFactory only at index time, not query time. There are some subtle but well-understood problems with synonyms at query time.
See: http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#solr.SynonymFilterFactory
After you move synonyms to the index analyzer chain, check that they are working with the Analysis page in the admin UI.
Upvotes: 2