Mothirajha
Mothirajha

Reputation: 1041

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.

Upvotes: 1

Views: 1169

Answers (1)

MeNyK
MeNyK

Reputation: 21

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.

Upvotes: 2

Related Questions