Topic: ThinkingSphinx not returning correct results

We currently have ThinkingSphinx working in its most basic mode, and we want to make our search form more complex.

Our model has the following definition;

class Article < ContentType
  has_many :content_images, :as => :content, :dependent => :destroy
  has_many :images, :through => :content_images
  accepts_nested_attributes_for :content_images
  
  define_index do
    indexes asset.short_desc, :as => :content
    indexes content, :as => :article_text
    set_property :delta => :datetime, :threshold => 1.hour
  end
end

As a test, we can push any string into ts using the following command;

@search = ThinkingSphinx.search @search_string, :classes => [Article]

In our test data, I use strings which appear in only one place - for example, we can search for the phrase PTCXXX.

When I search for only that string, I get only the one record back. Our log returns the following;

[Thu Jun  9 09:24:27.490 2011] 0.000 sec [all/2/rel 1 (0,10)] [article_core,article_delta] PTCXXX

- so we get one record back.

When I try to tell ThinkingSphinx to search for the phrase only in the Content field, it doesn't give me anything back (in the results below, you can see I've tried two different formats for the search - neither worked)

[Thu Jun  9 09:24:08.132 2011] 0.026 sec [all/2/rel 0 (0,10)] [article_core,article_delta] @article_text "PTCXXX"
[Thu Jun  9 09:17:53.339 2011] 0.000 sec [all/2/rel 0 (0,10)] [article_core,article_delta] @article_text=>"PTCXXX"

I've rebuilt the ts indexs and restarted the service - as you can see, a basic search works, but when I try to restrict the search to specific fields, it fails. I'm sure I'm doing something wrong that's pretty basic - but I can't spot it.

All help gratefully recieved!

Pete.

Re: ThinkingSphinx not returning correct results

Sorted!

I'd forgotten to specify the correct match mode, which then allows me to search by field names.

So my search now becomes

@search = ThinkingSphinx.search @search_string, :match_mode => :extended, :classes => [Article]

trying this with a search of @article_text "PTCXXX"

[Thu Jun  9 09:49:28.741 2011] 0.000 sec [ext/2/rel 1 (0,10)] [article_core,article_delta] @article_text "PTCXXX"

You'll see that the match mode parameter is now 'ext', and the search returns one record - exactly what I wanted.

Hope this is useful to someone else also!

Pete.