如何使用带有rails的Thinking_sphinx搜索显示更多记录

发布于 2024-09-06 17:30:31 字数 103 浏览 7 评论 0原文

我已经使用 Thinking_sphinx gem 更新了我的搜索字段记录,并且已经配置了它。它工作正常,但问题是,默认情况下它只显示 20 条记录。如何更改这些内容以使更多记录在视图中可见。

I have updated my searching fields records with thinking_sphinx gem and I have configured it. It is working fine but the problem, It is only displaying 20 records which is default. How to change those thing to make more records visible on view..

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

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

发布评论

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

评论(4

我不咬妳我踢妳 2024-09-13 17:30:31

Neutrino 几乎是正确的...

首先,值得注意的是 Sphinx(以及 Thinking Sphinx)总是对请求进行分页,默认页面大小为 20。如果您想更改它,可以传入 :每页 => 30 或类似的值来获取您想要的每页记录数。

Model.search 'foo', :per_page => 42

其次,Sphinx(默认情况下)将可用搜索结果的总数默认限制为 1000 个。这就是 Neutrino 所指出的 - 如果你设置 max_matches,你可以增加该值。但是,您还需要在搜索调用中指定 :max_matches 的值。

Model.search 'foo', :max_matches => 10_000

当您更改 config/sphinx.yml 文件中的值时,您将需要停止/重新索引/重新启动 - 有一个 rake 任务可以执行此操作:

rake ts:rebuild

这将确保生成的配置文件已启动- 迄今为止,Sphinx 守护进程已意识到这些更改。

Neutrino is almost correct...

Firstly, it's worth noting that Sphinx (and so, Thinking Sphinx) always paginates requests, and the default page size is 20. If you'd like to change that, you can pass in :per_page => 30 or similar to get the number of records per page that you'd like.

Model.search 'foo', :per_page => 42

Secondly, Sphinx (by default) limits the total number of available search results to 1000 by default. This is what Neutrino was pointing out - if you set max_matches, you can increase that value. However, you will also need to specify a value for :max_matches in your search call as well.

Model.search 'foo', :max_matches => 10_000

You will need to stop/re-index/restart when you change values in your config/sphinx.yml file - there's a single rake task that does this:

rake ts:rebuild

This will ensure that the generated configuration file is up-to-date, and the Sphinx daemon is aware of the changes.

最佳男配角 2024-09-13 17:30:31

在控制器中

@sphinx = Ad.search(params[:search], :per_page => 1000)

这对我有用。

In controller

@sphinx = Ad.search(params[:search], :per_page => 1000)

That's worked for me.

过度放纵 2024-09-13 17:30:31

在您的 config/sphinx.yml 中(如果您还没有,请创建一个)添加以下内容:

development:
  max_matches: 10000
# ... repeat for other environments

请参阅 文档 了解更多信息。

In your config/sphinx.yml (create one if you don't already have it) add the following:

development:
  max_matches: 10000
# ... repeat for other environments

See the docs for more info.

淡淡绿茶香 2024-09-13 17:30:31

我尝试了所有方法来获取 20 多个结果。

在配置文件中,我将 max_matches 设置为 1000,

然后它也只给了我 20 个结果。

然后我尝试了:per_page => 200,然后我得到了更多的结果。

感谢您的帮助。

I tried all the things for fetching more than 20 results.

In config file I putted max_matches to 1000,

Then also it was giving me only 20 results.

Then I tried :per_page => 200, and then I got the more number of result.

Thanks for help.

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