Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr search using contains, sound like

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

like image 904
Sriwantha Attanayake Avatar asked Mar 21 '14 07:03

Sriwantha Attanayake


3 Answers

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.

like image 81
Zac Avatar answered Sep 22 '22 13:09

Zac


Things you are asking, the first one is definitely achievable from Solr. I don't know about soundex.

1)How to search solr for contains You can store data into string type of field or text type of field. In string field by wild card searching you can achieve the result (E.g field1:"John*"). Also you should look into different types of analyzers. But before everything, please look into the Solr reference http://wiki.apache.org/solr/.

like image 23
buddy86 Avatar answered Sep 26 '22 13:09

buddy86


def self.get_search_deals(search_q, per = 50)
  data =  Sunspot.search(Deal) do
    fulltext '*'+search_q +'*', fields: :title
    paginate page: page_no, per_page: per
  end
  data.results
end

searchable do
  text    :title
end

just pass string as "*sam*"
like image 26
bk chovatiya Avatar answered Sep 23 '22 13:09

bk chovatiya