简体   繁体   中英

how to display more records on searching with Thinking_sphinx with rails

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..

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.

In controller

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

That's worked for me.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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