Counting the total occurrences of terms

52 views
Skip to first unread message

Dandan

unread,
Jan 10, 2012, 6:55:32 AM1/10/12
to Thinking Sphinx
Hi,

I'm trying to get the total occurrences that a search term appears in
text. For example if the search term is "blue" and I have two records
to search: "the blue blue sky" and "a blue day under a blue sky" I
would want a total of 4.

If possible from there, in some cases I will be grouping the totals of
word by another field in the table.

Any ideas? Thanks!

Pat Allan

unread,
Jan 21, 2012, 11:45:55 PM1/21/12
to thinkin...@googlegroups.com

Hi

I'm afraid Sphinx doesn't provide that level of detail - you'd have to scan through the results yourself to figure out how many times it matched in the Ruby side of things.

--
Pat

> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> 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.
>

Timo Virkkala

unread,
Jan 23, 2012, 8:25:10 AM1/23/12
to thinkin...@googlegroups.com
Hi Dandan,

Wouldn't ThinkingSphinx::Search#results[:words] do what you need?

ThinkingSphinx.search('blue').results[:words]
=> {"blue"=>{:docs=>2, :hits=>4}}

-T-

Dandan

unread,
Jan 25, 2012, 1:46:11 AM1/25/12
to Thinking Sphinx
Hey Timo,

Yip results[:words] did the trick. I haven't yet been able to see how
to split that up based on facets which I would like to use for
graphing data yet though. If you have any ideas let me know, otherwise
thanks for the initial answer.

Dan
Reply all
Reply to author
Forward
0 new messages