user2260040
user2260040

Reputation: 1380

SOLR search and synonyms

I have implemented an address search using SOLR and want to replace some text at query time with a space. Eg., if someone enters a word like "undefined" I want it to be replaced by a blank.

So, 5 Ford Undefined Street becomes 5 Ford Street

I have implemented synonyms eg.

lt => little

How do I go on defining so that at the query time, Undefined translates to a space?

Schema definitions for query is as follows:

 <analyzer type="query">
      <filter class="solr.PatternReplaceFilterFactory" pattern="([,]+)" replacement=" " replace="all"/>      
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.SynonymGraphFilterFactory" synonyms="synonyms.txt"/>
      <filter class="solr.FlattenGraphFilterFactory"/>      
    </analyzer>

Upvotes: 0

Views: 43

Answers (1)

MatsLindh
MatsLindh

Reputation: 52792

If you want to remove tokens you can use the plain old StopFilter. While most people think of the filter as used for removing non-relevant words such as the and of, it can be used with any wordlist.

Add Undefined (and other words you want to have removed) to a wordlist and add a stopfilter to your analysis chain:

<filter name="stop" words="stopwords.txt" />
or
<filter class="solr.StopFilterFactory" words="stopwords.txt"/>

Upvotes: 1

Related Questions