Ordering methods on ThinkingSphinx::Search

2 views
Skip to first unread message

murilasso

unread,
Nov 18, 2009, 12:21:14 PM11/18/09
to Thinking Sphinx
Hello,

I'd like to create 'order by' links in my views, and I'm wanting to do
that using Thinking Sphinx. I looked at Searchlogic, that is a nice
alternative to implement that feature, but I really don't want another
plugin in my application.

What I want is a 'order' method for ThinkingSphinx::Search, but for
that i'd need to hack a little on the TS library, which isn't great
either.

What you guys think of that? I think TS could be faster on ordering
search results, but Searchlogic makes it really simple.

I'm open for comments.

--
Murilo Soares Pereira
http://www.comp.ufscar.br/~murilo

Pat Allan

unread,
Nov 18, 2009, 7:07:31 PM11/18/09
to thinkin...@googlegroups.com
Hi Murilo

Why not create a sphinx_scope called order, which does what you need
it to do? I'm not that familiar with SearchLogic, so I'm not quite
sure what functionality you'd like.

--
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.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=
> .
>
>

murilasso

unread,
Nov 19, 2009, 8:34:31 AM11/19/09
to Thinking Sphinx
Let's suppose I have a search box that searches through the 'Person'
model, that has the 'full_name' and 'address' attributes.

In the 'Person' controller, there's a 'search' method, that takes the
query (as params[:query]) from the view:
@search = Person.search params[:query]

After filling the '@search' variable, the 'search' method renders the
'show' action. So far so good.

What I want, is that I have 'sort by' links in my views, like 'Sort by
name' and 'Sort by address'.

I wanted to do a method, to order like this: @search.sort_by(:field).
I think that is the cleanest way of doing this.

What do you guys think?

--
Murilo Soares Pereira
http://www.comp.ufscar.br/~murilo

Pat Allan

unread,
Nov 19, 2009, 8:45:33 AM11/19/09
to thinkin...@googlegroups.com
The following in your model, after the define_index block, should do
the trick:

sphinx_scope(:sort_by) { |field|
{:order => field}
}

--
Pat

murilasso

unread,
Nov 19, 2009, 8:57:46 AM11/19/09
to Thinking Sphinx
That's what I was talking about.. thank you very much Pat.

--
Murilo Soares Pereira
http://www.comp.ufscar.br/~murilo

Reply all
Reply to author
Forward
0 new messages