Reputation: 1751
I want to do a searchbar to search a term in many fields of my model. For now I have this code :
@query_search = "#{params[:search]}"
products = Campaign.search query: {match: {name: @query_search}}, fields: [{owner: @query_search}], misspellings: {distance: 2}
the result works only on the name
fields (and only on the exact case). the fields: [{owner: @query_search}]
change nothing.
I tried to do things like this :
products = Campaign.search query: {match: {name: @query_search, brief: @query_search}}, fields: [{owner: @query_search}], misspellings: {distance: 2}
but no result, misspellings don't work either in any case.
So, Anybody has an idea? Thanks !
Upvotes: 1
Views: 1434
Reputation: 2465
You need to use elasticsearch
cross_fields
or query_string
feature to search in more than one fields with one term. Unfortunately searchkick
does not support it and you have to do it by yourself.
You can follow the example of my answer to this stackoverflow question.
Upvotes: 0
Reputation: 4713
What Andrew said, and just try running the regular search:
products = Campaign.search(
params[:search],
misspellings: {distance: 2}
)
It should generate a query with multi_match across all fields by default anyway.
Upvotes: 0
Reputation: 3236
The query
option tells Searchkick to use the exact query you provide, so the other options will be ignored.
Upvotes: 1