Senthil Kumar Bhaskaran
Senthil Kumar Bhaskaran

Reputation: 7461

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

Upvotes: 1

Views: 1209

Answers (4)

whitesiroi
whitesiroi

Reputation: 2843

In controller

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

That's worked for me.

Upvotes: 1

Swapnil Chincholkar
Swapnil Chincholkar

Reputation: 2909

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.

Upvotes: 0

pat
pat

Reputation: 16226

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.

Upvotes: 4

alex.zherdev
alex.zherdev

Reputation: 24164

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.

Upvotes: 0

Related Questions