Searchkick neo4j:搜索不工作?
Searchkick neo4j: search not working?
我用过gemsearchkick
&gemneo4j
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
我也想得到所有结果,请帮帮我?
布莱恩建议
(User.search('su', fields: [:first_name, :last_name], misspellings: {edit_distance: 2})).map(&:first_name)
=> ["Sam", "Marilet", "aa", "asd", "Maricel"]
(User.search('sure', fields: [:first_name, :last_name], misspellings: {edit_distance: 3})).map(&:first_name)
=> ["Herlinda", "Brent", "Andy", "suresh"]
您应该可以使用 edit_distance
选项:
https://github.com/ankane/searchkick#misspellings
示例:
User.search('suresh', fields: [:first_name, :last_name], misspellings: {edit_distance: 2})
在查看@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)
修改后别忘了re-index数据User.reindex
我用过gemsearchkick
&gemneo4j
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
我也想得到所有结果,请帮帮我?
布莱恩建议
(User.search('su', fields: [:first_name, :last_name], misspellings: {edit_distance: 2})).map(&:first_name)
=> ["Sam", "Marilet", "aa", "asd", "Maricel"]
(User.search('sure', fields: [:first_name, :last_name], misspellings: {edit_distance: 3})).map(&:first_name)
=> ["Herlinda", "Brent", "Andy", "suresh"]
您应该可以使用 edit_distance
选项:
https://github.com/ankane/searchkick#misspellings
示例:
User.search('suresh', fields: [:first_name, :last_name], misspellings: {edit_distance: 2})
在查看@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)
修改后别忘了re-index数据User.reindex