Rails 3 和 mongo db (mongoid) 中的基本文本搜索

发布于 2024-12-23 08:01:14 字数 221 浏览 0 评论 0原文

我有一些漂亮的 javascript 可以序列化搜索输入。

控制器有这个:

@recipes = Recipe.where(name: params[:q])

现在它只在存在精确的完整单词匹配时才返回结果 - 有谁知道如何使其返回可能包含 params[:q] 的结果,即使它不是精确的完整匹配?

即鸡肉应返回炖鸡、鸡肉馅饼等。

I have some nifty javascript that serializes search input.

the controller has this:

@recipes = Recipe.where(name: params[:q])

right now it only returns results when theres an exact full word match - does anyone know of a way to make it return results which might contain the params[:q] even if its not an exact full match?

i.e. chicken should return chicken stew, chicken pot pie, etc.

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

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

发布评论

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

评论(1

情丝乱 2024-12-30 08:01:14

试试这个:

@recipes = Recipe.where(name: /#{params[:q]}/i)

Try this one:

@recipes = Recipe.where(name: /#{params[:q]}/i)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文