Hi Stan
I think the issue could be that you're requesting the :any match mode, but
searching on specific fields requires :extended or :extended2. Indeed, when you
use conditions, the match mode defaults to :extended.
So, try removing your explicit match mode, see if that works a bit better.
If you want *any* word to match in either of the fields, then what you may want
to do is something like the following:
Feature.search("@(title, subtitle) #...@search}", :match_mode => :extended,
:max_matches => 50, :per_page => 50)
That will make sure *all* query terms appear in *either* title or subtitle. If
you want *any* of the query terms to appear in either title or subtitle, then
you're going to need to break down @search and insert |'s (they act as ORs).
require 'shellwords' # Part of Ruby Standard Library
# ...
@search = '(' + Shellwords.split(@search).collect { |word|
"\"#{word}\""
}.join(" | ") + ')'
Shellwords respects quotes around multiple words - eg: 'foo "bar baz"' becomes
['foo', 'bar baz'].
Have a read through the docs for the extended match mode, that should make
things a bit clearer.
http://www.sphinxsearch.com/docs/manual-0.9.9.html#matching-modes
Cheers
--
Pat
On 19/11/2010, at 12:52 PM, stasch wrote:
> I have a search box on my site which retrieves model instances that
> contain the search term in any of three fields. Here is the code I am
> using:
>
> results = Feature.search(:match_mode => :any, :conditions => { :title
> => @search, :subtitle => @search, :description =>
> @search }, :max_matches => 50, :per_page => 50)
>
> Where Feature is the name of the model and @search contains the search
> term. I am getting rather peculiar results. If I have multiple
> matches, I sometimes get an extra record that does not contain the
> search term in any of the fields. It is always one of two records
> which happen to be duplicates of each other. If I have no matches, I
> just get one of the extra records.
>
> Is my syntax wrong or should I be looking for a corrupt index? How
> would I fix the corrupt index if that is what's going on?
>
> Thanks for your help
>
> Stan
>
> --
> You received this message because you are subscribed to the Google Groups
> "Thinking Sphinx" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/thinking-sphinx?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/thinking-sphinx?hl=en.