Search code examples
solrsynonym

"Is-a" relationship in Solr Synoyms


I have two texts:

Text-1

Our new Android Smartphone

Text-2

Our new iPhone Smartphone

I would like to tell Solr that "android" is a "smartphone".

Expected results:

If the user searches for "Android" only the first text should be found.

If the user searches for "Smartphone" both texts should be found.

If I use "equal synonyms" (SolrSynonymParser) (during indexing), then the term "Smartphone" would get expanded to "Smartphone, Android, iPhone" in both texts.


Solution

  • In addition to the comment of MatsLindh, to add an unidirectional synonym like: "android=>android,smartphone", you should also consider to add the Synonym Filter only at index time and not both at index and query time

    For example:

    <analyzer type="index"> 
       ...
       <filter class="solr.SynonymGraphFilterFactory" synonyms="synonyms.txt"/>
       ... 
    </analyzer>
    

    This way, both "android" and "smartphone" will be indexed for any occurrence of "android"