I am trying to setup Searchkick in my Rails application.
I have a model with fields:
NK4321nn1234
What I need:
1nn1
should find NK4321nn1234
1NN1
should NOT find NK4321nn1234
Here is my model:
class Product < ApplicationRecord
searchkick word_middle: [:number]
def search_data
{
number: number
}
end
def self.sensitive_search query, page
search( query,
fields: [{number: :exact}],
match: :word_middle,
misspellings: false,
page: 1,
per_page: 15
)
end
def self.insensitive_search query, page
search( query.downcase,
fields: [:number],
match: :word_middle,
misspellings: false,
page: 1,
per_page: 15
)
end
end
Case-sensitive search does not work. As far as I understand, searchkick downcase all nGrams
during indexing... But why?..
Questions:
My environment: rails 5.2.0, searchkick 3.1.0
As of this commit , you can do:
class Product < ApplicationRecord
searchkick word_middle: [:number], case_sensitive: true
end
Be sure to reindex after updating Searchkick options.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.