简体   繁体   中英

Wildcard search using SearchKick

Is there any way to use wildcard after a word and before a word as mentioned below..

User.search "*" + "admi"+"*"

or any other solution to solve such problems using SearchKick gem.

Hope it's not too late.

You want the keyword to be appeared in the middle of the text, right? You should use Partial Matches as your search option.

For example, in model User:

class User < ActiveRecord::Base
  searchkick text_middle: [ :name ]
end

Searching:

User.search("admi", fields: [{name: :text_middle}]).each do |user|
  # Do something with user
end

If the search result is empty, try User.reindex before a search.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM