如何使用带有rails的Thinking_sphinx搜索显示更多记录
我已经使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Neutrino 几乎是正确的...
首先,值得注意的是 Sphinx(以及 Thinking Sphinx)总是对请求进行分页,默认页面大小为 20。如果您想更改它,可以传入
:每页 => 30
或类似的值来获取您想要的每页记录数。其次,Sphinx(默认情况下)将可用搜索结果的总数默认限制为 1000 个。这就是 Neutrino 所指出的 - 如果你设置 max_matches,你可以增加该值。但是,您还还需要在搜索调用中指定
:max_matches
的值。当您更改 config/sphinx.yml 文件中的值时,您将需要停止/重新索引/重新启动 - 有一个 rake 任务可以执行此操作:
这将确保生成的配置文件已启动- 迄今为止,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.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.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:This will ensure that the generated configuration file is up-to-date, and the Sphinx daemon is aware of the changes.
在控制器中
这对我有用。
In controller
That's worked for me.
在您的 config/sphinx.yml 中(如果您还没有,请创建一个)添加以下内容:
请参阅 文档 了解更多信息。
In your
config/sphinx.yml
(create one if you don't already have it) add the following:See the docs for more info.
我尝试了所有方法来获取 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.