Search code examples
ruby-on-railsrubyrubygemssphinxthinking-sphinx

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


Solution

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