I have a table which has job_title field,
I want to make a fuzzy search let user can still get the result when they mis-spell query keyword.
For example, I have many records have the "Android developer" as its job_title,
When the user issues the incorrect search Job.es_qsearch("Andoirddd")
, it should work as well by the help of NGRAM_ANALYZER
However, I could get any results from the incorrect keyword.
I can only get the result when I type Job.es_qsearch("Android")
How could I achieve the search result as I expect.
Thanks
job.rb
NGRAM_ANALYZER = {analysis: {
filter: {
autocomplete_filter: {
type: "edge_ngram",
min_gram: 3,
max_gram: 20
}
},
analyzer: {
ngram_analyzer: {
type: :custom,
tokenizer: :standard,
filter: [
:lowercase,
:autocomplete_filter
]
}
}
}}
settings NGRAM_ANALYZER do
mappings do
indexes :job_title, include_in_all: 'ngram_analyzer'
indexes :description, include_in_all: 'ngram_analyzer'
end
end
def self.es_qsearch(*args, &block)
q_params = {
multi_match: {
query: "*#{args}*",
fields: ['job_title^5', 'description']
}
}
__elasticsearch__.search(
{
query: q_params,
}
)
end
I used Fuzzy Query but it's still not working
Fuzzy Query sent this query to ES search
{:index=>"jobs",
:type=>"job",
:body=>{:query=>{:bool=>{:must=>[{:fuzzy=>{:description=>{:value=>["electrical"], :fuzziness=>2}}}]}}, :size=>200}},
Fuzzy Query 1: not working
"bool": {
"must": [
{
"fuzzy": {
"description": {
# min_similarity: 0.4,
"value": args,
# prefix_length: 0,
"fuzziness": 2
}
},
}]
}
Fuzzy Query 1: not working
"fuzzy": {
"description": {
# min_similarity: 0.4,
"value": args,
# prefix_length: 0,
"fuzziness": 2
}
},