pat / thinking-sphinx

Sphinx/Manticore plugin for ActiveRecord/Rails
http://freelancing-gods.com/thinking-sphinx
MIT License
1.63k stars 468 forks source link

:with argument not working properly? #239

Closed Bodacious closed 13 years ago

Bodacious commented 13 years ago

Hey man...

Here's my index rules in my Story model:

  define_index do
    indexes title
    indexes description
    indexes transcript
    indexes taggings.tag.name, :as => :tags

    has state, story_type, vertical_id, user_id, created_at, published_at

    set_property :field_weights => {
      :tags        => 1,      
      :description => 10,
      :transcript  => 15,
      :title       => 20,
    }
  end

When I do:

Story.search("the", :with => { :vertical_id => vertical.id }) # => 25 results

but when I add

Story.search("the", :with => { :vertical_id => vertical.id, :state => "published"}) # => 0 results

I know there are results in the DB that match that query so it seems that TS doesn't like my "state" attribute. State is just a string field - almost all of the records on the db stories table are state = 'published'.

Am I doing something wrong here or is this a bug?

Ruby 1.9.2 Rails 3.1.0.rc4

pat commented 13 years ago

The problem is that Sphinx doesn't allow filtering on string attributes - there's a suggestion or two for a work-around in the documentation: http://freelancing-god.github.com/ts/en/common_issues.html#string_filters

On 13/06/2011, at 2:58 AM, Bodacious wrote:

Hey man...

Here's my index rules in my Story model:

 define_index do
   indexes title
   indexes description
   indexes transcript
   indexes taggings.tag.name, :as => :tags

   has state, story_type, vertical_id, user_id, created_at, published_at

   set_property :field_weights => {
     :tags        => 1,      
     :description => 10,
     :transcript  => 15,
     :title       => 20,
   }
 end

When I do:

Story.search("the", :with => { :vertical_id => vertical.id }) # => 25 results

but when I add

Story.search("the", :with => { :vertical_id => vertical.id, :state => "published"}) # => 0 results

I know there are results in the DB that match that query so it seems that TS doesn't like my "state" attribute. State is just a string field - almost all of the records on the db stories table are state = 'published'.

Am I doing something wrong here or is this a bug?

Ruby 1.9.2 Rails 3.1.0.rc4

Reply to this email directly or view it on GitHub: https://github.com/freelancing-god/thinking-sphinx/issues/239

Bodacious commented 13 years ago

So this was an RTFM issue.

I've bought the Thinking Sphinx PeepCode PDF to rectify this

Bo