Solr 搜索使用包含,听起来像 [英] Solr search using contains, sound like
问题描述
问题:我在 solr 中有电影信息.两个字符串字段定义电影标题和导演姓名.复制字段定义了 solr 搜索默认的另一个字段.
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)如何在solr中搜索包含
例如a) 如果电影导演的名字是John Cream",搜索joh 不会返回任何东西.但是,搜索 John 返回正确的结果.
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) 如果有一个名为 aaabbb 的电影名和另一个名为 aaa 的电影名,则搜索 aaa 只会返回一个结果.我需要返回这两个结果.
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) 如何解决拼写错误
例如如果电影导演姓名为John Cream",则搜索 Jon 不会返回任何结果.solr 是否有一个很好的听起来像(soundex)的实现.如果是如何启用它?
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?
您可以使用 solr 查询语法
推荐答案
显然可以使用通配符搜索 contains(例如:title:*aaa*
将匹配 'aaabbb' 和 'cccaaabbb'),但要小心,因为它不能有效地使用索引.你真的需要这个吗?
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?
可以将 solr.PhoneticFilterFactory
过滤器应用于您的索引和查询,从而实现类似 soundex 的搜索.要实现这一点,请在架构中像这样定义您的 fieldType:
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>
如果您将director"字段定义为text_soundex",您将能够搜索Jon"并找到John"
If you define your "director" field as "text_soundex" you'll be able to search for "Jon" and find "John"
有关详细信息,请参阅 http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters.
See http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters for more information.
这篇关于Solr 搜索使用包含,听起来像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!