Think Sphinx 多个表单字段

发布于 2025-01-06 19:07:20 字数 485 浏览 3 评论 0原文

一直在努力解决这个问题...

表单截图: https://i.sstatic.net/PBWMW.jpg

字段名称/ID: 名称 |电子邮件 |公司 ID | user_type

控制器:

@users = User.search(params[:name], params[:email], params[:company_id], params[:user_type])

模型:

define_index do
   indexes :name
   indexes :email
   indexes :company_id
   indexes :user_type
end

执行此操作的正确方法是什么,已搜索文档但找不到任何有用的信息:(

Have been really struggling with this...

Form screenshot: https://i.sstatic.net/PBWMW.jpg

Field name's/id's:
name | email | company_id | user_type

Controller:

@users = User.search(params[:name], params[:email], params[:company_id], params[:user_type])

Model:

define_index do
   indexes :name
   indexes :email
   indexes :company_id
   indexes :user_type
end

What is a proper way of doing this, have searched documentation but could not find any useful information :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

筑梦 2025-01-13 19:07:20

通过 Sphinx 按字段搜索最简单的方法是传递哈希值。您可以消除nil-s以确保thinking_sphinx将查看传入的请求

conditions = {}
%w(name email company_id user_type).each do |i|
  i = i.to_sym
  next unless params[i]
  conditions[i] = params[i]
end

User.search(:conditions => conditions)

The simplest searching method by fields through Sphinx is to pass a hash. You can eliminate nil-s to ensure that thinking_sphinx will be looking through the incoming request

conditions = {}
%w(name email company_id user_type).each do |i|
  i = i.to_sym
  next unless params[i]
  conditions[i] = params[i]
end

User.search(:conditions => conditions)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文