我使用了宝石searchkick
&宝石neo4j
class User
include Neo4j::ActiveNode
property :first_name
property :last_name
property :email
searchkick callbacks: :async
def search_data
{
first_name: first_name,
last_name: last_name,
email: email
}
end
end
(User.search'suresh',fields:[:first_name,:last_name])。count => 22
(User.search'sures',fields:[:first_name,:last_name])。count => 0
即使我输入Su
,我也希望得到所有结果,请帮帮我?
Brian建议
(User.search('su',fields:[:first_name,:last_name],拼写错误:{edit_distance:2}))。map(&:first_name)
=> [“Sam”,“Marilet”,“aa”,“asd”,“Maricel”]
(User.search('sure',fields:[:first_name,:last_name],拼写错误:{edit_distance:3}))。map(&:first_name)
=> [“Herlinda”,“Brent”,“Andy”,“suresh”]
答案 0 :(得分:1)
您应该可以使用edit_distance
选项:
https://github.com/ankane/searchkick#misspellings
示例:
User.search('suresh', fields: [:first_name, :last_name], misspellings: {edit_distance: 2})
答案 1 :(得分:0)
在查看了@brains的建议并进行了更多研究后,我能够通过跟踪更改来实现它
更新后的模型如下:
class User
include Neo4j::ActiveNode
property :first_name
property :last_name
property :email
searchkick word_start: [:first_name, :last_name]
def search_data
{
first_name: first_name,
last_name: last_name
}
end
更新后的查询如下:
users = User.search('su', operator: "or",
fields: [:first_name, :last_name],
misspellings: {below: 5},
match: :word_start,
where: {id: mutual_stay_pal_ids},
page: params[:page], per_page: 10)
更改后不要忘记重新索引数据User.reindex