Why it doesn't work:
If you add a string as an attribute, then Sphinx stores it as an  
integer, based on the alphabetical order of the attribute's values  
across all documents. Thinking Sphinx can't figure out this value, and  
so can't really filter on it.

How it could work:
Use the CRC functionality, something like:
   has 'CRC32(source)', :as => :source, :type => :integer

   Project.search 'some text', :with => {:source =>  
'someSource'.to_crc32}

Faceting won't work on this manual attribute, so you'd probably want  
to call it something else, and keep the existing attribute with the  
facet flag.

Why would you use attributes instead of fields:
Field comparison is all done via the query string, and so Sphinx will  
use weightings and rankings and other such calculations if you're  
limiting a query by a certain field value. It also forces  
the :extended match_mode, which may not be desirable.

Attributes, on the other hand, are straight comparisions - integers to  
integers, floats to floats, booleans to booleans. There's no extra  
complexity, which means it's almost certainly going to be faster (I've  
not done any benchmarks on this, though). It also doesn't change the  
match_mode.


Hope that adds some clarity - I really should add something like this  
to the documentation :)

-- 
Pat

On 17/08/2009, at 4:06 PM, Christian Aust wrote:

>
> Note to self: I didn't mistake "src" for "source" in my actual ruby
> code. Sorry for the confusion.
>
> On 17 Aug., 17:04, Christian Aust <[email protected]>
> wrote:
>> Hi all,
>>
>> my model Project features an attribute "source" which contains only a
>> small number of possible string entries. I won't do text-searching
>> based on that property, so I figured an attribute would be well in
>> order.
>>
>> has :source, :facet=> true
>>
>> Based in the docs, I tried to search like this:
>>
>> Project.search 'some text', :with=> { :src => "someSource" }
>>
>> to find all projects containing "some text" that would have a source
>> attribute of "someSource". The search returned nothing. I checked the
>> sphinx result by using the command-line search client and found that
>> my attribute "src" contained some integer value instead of a string.
>>
>> Then I changed the code in define_index, and added my src field using
>> "indexes". Now it worked.
>>
>> When and for what would I use an attribute, and when would I need a
>> field? Any help is greatly appreciated. Regards,
>>
>> Christian
> >


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to