public
Description: Sphinx plugin for Rails and Merb
Home | Edit | New

FAQ

Q: How do I apply stemming?
Sphinx comes with a built-in stemmer, or you can re-compile sphinx with the --with-stemmer flag.
Q: How do I see the relevance (weight) of each search match?
Like this:

    @results.each_with_weighting do |result, weight|
       ...
    end
Q: What are the sort modes?
Each sort mode is available by the corresponding key in the search hash: For SPH_SORT_EXPR, you would set :sort_mode => :expr. (See the sphinx docs for a list). For example, to balance search relevance with some sort of independently-determined score:

    @results ||= Post.search(self.query,
      :sort_mode             => :expr,
      :sort_by               => '(@weight * 0.01) + score',
      :match_mode            => :extended,
      :page                  => params[:page]
      )
Q: Sphinx global settings
The contents of RAILS_ROOT/config/sphinx.yml are injected into the actual sphinx .conf file.
Example:

defaults: &defaults
  max_matches: 2000
  # http://www.sphinxsearch.com/docs/current.html#conf-stopwords
  stopwords: 'config/sphinx/stopwords.txt'
  # http://www.sphinxsearch.com/docs/current.html#conf-wordforms
  wordforms: 'config/sphinx/wordforms.txt'
  # http://www.sphinxsearch.com/docs/current.html#conf-morphology
  morphology: libstemmer_en
development:
  << *defaults
production:
  << *defaults
staging:
  << *defaults
test:
  << *defaults

Interesting global settings inlude:
Wildcarding:

  enable_star: 1
  min_infix_len: 1
Q: I installed Sphinx as a frozen gem instead of a plugin. I can’t see the rake tasks
Add the following lines to your Rakefile:

Dir.glob(File.join(File.dirname(__FILE__), 'vendor/gems/*/tasks/rails.rake')) do |tasksfile|
  load tasksfile
end

More details: https://rails.lighthouseapp.com/projects/8994/tickets/59
Last edited by mreinsch, Tue Jul 21 02:32:49 -0700 2009
Home | Edit | New
Versions: