Sohan
Sohan

Reputation: 3807

Solr synonyms with space

My data model:

Dress
|-kind
|-color
|-for_season

I want to search the model for a specific season as well as for all seasons, like as follows:

Search Query: all seasons

Should Match: Winter, Spring, Summer, Fall

I have the following line in my synonyms file:

all\s seasons: winter, spring, summer, fall

I am doing it query time and I see the solr admin panel analyze page showing the synonyms in the term column. However, when I search for for_season:all seasons I don't get any result.

Any idea why? Appreciate your time on this.

Edit:

Here's what I found:

  1. I had to escape the synonyms appearing on the right hand side, as follows:

    all news => weather\ forecast, sports, ...
    
  2. At query time, I had to wrap the query in double quotes. as follows:

    my_field:"all news"
    
  3. I had to put the original word on the RHS as it won't find that unless it was repeated.

    news => news, weather\ forecast, sports, ...
    

It looks to be working fine now. Thanks for your time.

Upvotes: 1

Views: 2984

Answers (2)

Tomasz Szymulewski
Tomasz Szymulewski

Reputation: 2073

Generally there is a problem with multi-term synonyms (e.g. 'all seasons') in Apache Solr. Description of this problem you can find here:

and here you can find a nice solution of this problem:

https://lucidworks.com/blog/2014/07/12/solution-for-multi-term-synonyms-in-lucenesolr-using-the-auto-phrasing-tokenfilter/

Upvotes: 0

rfeak
rfeak

Reputation: 8204

Space isn't a delimiter in the synonym configuration file. You shouldn't have to escape it.

Per documentation here: http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#solr.SynonymFilterFactory

This should just be

all seasons => winter, spring, summer, fall

Upvotes: 2

Related Questions