multi value float attribute

117 views
Skip to first unread message

mohitnegi

unread,
Sep 21, 2011, 1:56:18 AM9/21/11
to thinkin...@googlegroups.com
How to search in a multi value float attribute.

I have a model which is having a has_many relationship with other model

when i create a sphinx index then in that attribute all the values are stored, now for sphinx search how to search each and every value..

Pat Allan

unread,
Sep 21, 2011, 2:00:03 AM9/21/11
to thinkin...@googlegroups.com
I'm afraid Sphinx has no concept of multi-value float attributes - only multi-value integer attributes.

Is it possible to search on the model that has the float column instead?

--
Pat

> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/8XhnYiQs090J.
> To post to this group, send email to thinkin...@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.

mohitnegi

unread,
Sep 21, 2011, 2:13:01 AM9/21/11
to thinkin...@googlegroups.com
Hi Pat,

Actually i have a model called profile and each profile can have multiple scores, so when i am building index on profile model
it looks like

has score(:overall_score)

where overall_score is a filed in score model.

now there is a has_many relationship between profile and score, so it's taking all the score for particular profile.

now when i am using Profile.search :with=>{:overall_score=>{22.9..99.9)}

then this query is only  searching the first value and ignoring the other score for that particular profile.

mohitnegi

unread,
Sep 21, 2011, 3:00:14 AM9/21/11
to thinkin...@googlegroups.com
Is there another way to achieve the same!!!!

Pat Allan

unread,
Sep 21, 2011, 7:39:14 PM9/21/11
to thinkin...@googlegroups.com
You're going to need to search on Score instead of Profile - but you could group by profile_id (provided you create it as an attribute), which will ensure you only get one score per profile in your search results.

--
Pat

On 21/09/2011, at 5:00 PM, mohitnegi wrote:

> Is there another way to achieve the same!!!!
>

> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.

> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/hXWspL19PYkJ.

mohitnegi

unread,
Sep 22, 2011, 2:43:01 AM9/22/11
to thinkin...@googlegroups.com
Hi Pat,

Another thought, Is there a way while indexing can i convert my float attribute to integer,

i.e. in sphinx search they will be stored as a integer values

something like 

has score(:overall_score).to_i, :as=>integer_overall_score, :type=>:integer                         

    (:overall_score is a float field in database)


then i can have a search on multivalue attribute.

Pat Allan

unread,
Sep 22, 2011, 3:21:40 AM9/22/11
to thinkin...@googlegroups.com
Sure, you could do that. You'll need to write a snippet of SQL though… are you using MySQL or PostgreSQL?

--
Pat

> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.

> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/r3_eJcRt-P0J.

mohitnegi

unread,
Sep 22, 2011, 4:05:59 AM9/22/11
to thinkin...@googlegroups.com
I am using mysql 

Pat Allan

unread,
Sep 22, 2011, 4:10:05 AM9/22/11
to thinkin...@googlegroups.com
Right, so something *like* this should do the job (you'll need to figure out the conversion bit):

has "CONCAT_WS(scores.overall_score, ',')", :as => :overall_scores, :type => :multi

# and to ensure the scores table/association is joined on:
join scores

Cheers

--
Pat

On 22/09/2011, at 6:05 PM, mohitnegi wrote:

> I am using mysql

>
> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.

> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/lfYdLoe8izUJ.

Reply all
Reply to author
Forward
0 new messages