Solr search using contains, sound like

Sriwantha Attanayake picture Sriwantha Attanayake · Mar 21, 2014 · Viewed 22.8k times · Source

Problem: I have a movie information in solr. Two string fields define the movie title and director name. A copy field define another field which solr search for default.

I would like to have google like search with limited scope as follows. How to achieve it.

1)How to search solr for contains

E.g. a) If the movie director name is "John Cream", searching for joh won't return anything. However, searchign for John return the correct result.

b) If there is a movie title called aaabbb and another one called aaa, searching for aaa returns only one result. I need to return the both results.

2) How to account for misspelling

E.g. If the movie director name is "John Cream", searching for Jon returns no results. Is there a good sounds like (soundex) implementation for solr. If so how to enable it?

You can use solr query syntax

Answer

Zac picture Zac · Mar 21, 2014

Searching for contains is obviously possible using wildcards (eg: title:*aaa* will match 'aaabbb' and also 'cccaaabbb'), but be careful about it, becouse it doesn't use indexes efficently. Do you really need this?

A soundex like search is possible applying solr.PhoneticFilterFactory filter to both your index and query. To achieve this define your fieldType like this in schema:

<fieldType name="text_soundex" class="solr.TextField">
...
<filter class="solr.PhoneticFilterFactory" encoder="Soundex" inject="true"/>
</fieldType>

If you define your "director" field as "text_soundex" you'll be able to search for "Jon" and find "John"

See http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters for more information.