Solr search using contains, sound like

荒凉一梦 提交于 2019-12-10 17:06:29

问题


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


回答1:


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.




回答2:


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/.




回答3:


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*"


来源:https://stackoverflow.com/questions/22552446/solr-search-using-contains-sound-like

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!