Hi David

Unfortunately, because Sphinx talks directly to the database, it  
doesn't know anything about model methods. If you'd like to achieve  
this, you have two options:

* Add another column to your model, called first_letter_name, which  
you can set on a before_save callback.
* Use a SQL snippet for the field definition:
   indexes "SUBSTR(name, 0, 1)", :as => beginning_letter

While the latter is perhaps neater from a maintenance perspective,  
facets won't work, because the reverse problem is true: the models  
can't execute the SQL snippet to determine the value (and Sphinx  
doesn't store strings). So, I recommend the first option.

-- 
Pat

On 03/12/2009, at 6:41 AM, MrSousa wrote:

> Hello,
>
> in my class User a have this method:
>
> def first_letter_name
>  self.name.first
> end
>
> Is there a way to index this method result as :beginning_letter for
> example?
> I want to facet search for the first letter of the name of each user.
>
> Example:
> define_index do
>    indexes name
>    indexes first_letter_name, :as => :beginning_letter, :facet =>
> true
>    indexes email
>    indexes status, :facet => true
> end
>
> Thanks,
>
> David Sousa
>
> --
>
> 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.


Reply via email to