简体   繁体   English

使用SearchKick进行通配符搜索

[英]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. 或使用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. 如果搜索结果为空, User.reindex在搜索之前尝试User.reindex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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