views:

53

answers:

2

I have this expression which is working as expected in Thinking Sphinx:

Customer.search :with => {:signer_id => 23}

but I need to write an expression with OR of some attributes, like signer_id is 23 or admin_level is 42, so I moved to extended match mode and wrote this:

Customer.search "@signer_id 23", :match_mode => :extended2

which according to my understanding of the Sphinx relevant documentation, it should be equivalent, but it doesn't match anything at all. Any ideas what am I doing wrong? How do I write an extended thinking sphinx expression?

Copied and pasted from the console:

ruby-1.8.7-p302 > Customer.search(:with => {:signer_id => 23}).count
 => 20 
ruby-1.8.7-p302 > Customer.search "@signer_id 23", :match_mode => :extended2
 => [] 
ruby-1.8.7-p302 > Customer.search("@signer_id 23", :match_mode => :extended2).count
 => 0

Update: fixed the id (32 -> 23).

A: 

I did this to do matching on fields that I have normalized out. This reduces the amount of churn in the db by having the same text in the full text search.

Querying: 'pizza | @product_codes (965|1636|1848|2939|4227|5067|5735) | @brand_codes (1485) | @service_codes (2782)

Note as the other answer points out you cannot do properties this way, these have to be indexed fields.

I brute force them out like this:

        indexes '(select group_concat(products.id) from business_products inner join products on (products.id = business_products.product_id) where business_id = `businesses`.`id` group by business_id)', :as => :product_codes, :type => :integer

Additionally you will need to reduce the number of characters in a word by setting this

  min_word_len: 1

Otherwise it won't match your 1 and 2 digit number codes.

Bill Leeper
I made the same mistake and an math olympic; they couldn't believe such an idiot like me actually won it ;) Anyway, I made the mistake only here, the code was fine and still not working.
J. Pablo Fernández
I rewrote my answer here.
Bill Leeper
A: 

I'm not spotting the section in the docs that says you can use the @attribute value syntax - it's only for fields, not attributes. At least, that's my understanding. Would be fantastic if I'm wrong :)

pat
What's the difference between fields and attributes?
J. Pablo Fernández
Fields are the textual data for your records - ie: all the words that should match against search queries. Attributes are integers, timestamps, booleans, floats to sort and filter results by. Have a read of the Fields and Attributes sections on this page: http://freelancing-god.github.com/ts/en/sphinx_basics.html
pat