Alternative for the command "search" ?

10 views
Skip to first unread message

UnConundrum

unread,
Jun 23, 2011, 9:41:29 PM6/23/11
to Thinking Sphinx
I'm adding TS to a rather mature application with 173 models.
Unfortunately, we have many "search" methods defined and it would take
days to go through the code and change everything. Is there any way
to customize the search command in TS to use something like ts_search
instead of just search?

My third issue today.... I'd be remiss not to thank you for all the
time and effort you're putting into the project. I for one, greatly
appreciate it.

Pat Allan

unread,
Jun 23, 2011, 9:57:37 PM6/23/11
to thinkin...@googlegroups.com
Unfortuantely, there's no easy way to customise the search method name...

Although, if you have your define_index block before your custom search method in the model, then it will overwrite TS's search method. And then, you could create your own ts_search method:

def ts_search(*args)
ThinkingSphinx::Search.new *search_options(args)
end

I've not tried this myself, but in theory it should work. Not sure if there's issues deeper within Thinking Sphinx where it expects Model.search to be there as per normal, though.

Cheers

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

UnConundrum

unread,
Jun 23, 2011, 11:00:35 PM6/23/11
to Thinking Sphinx
:(

Unfortunately, it doesn't seem to be working that way. Lets say I
have a model called History and one called Contact. My only index
block in the entire project is in History. In the controller, I'm now
calling History.ts_search, and that search works fine. Unfortunately,
when I want to go to the contact page and do a search with a
Contact.search, and there is a self.search method in the Contact
model, I get the "Missing Attribute for Foreign Key" error generated
by TS (see below). I have no index block defined in Contact. It's
like TS is doing the global search when it should be doing a model
search. Before I added the ts_search, I was doing a History.search,
not a ThinkingSphinx.search, so it should have been looking at just
History. I can't understand why it's looking at Contact. Any ideas?


RuntimeError (Missing Attribute for Foreign Key intranet_id):
/Users/user/.rvm/gems/ruby-1.8.7-p302/gems/thinking-sphinx-1.4.4/lib/
thinking_sphinx/active_record/has_many_association.rb:28:in
`attribute_for_foreign_key'
/Users/user/.rvm/gems/ruby-1.8.7-p302/gems/thinking-sphinx-1.4.4/lib/
thinking_sphinx/active_record/has_many_association.rb:32:in
`default_filter'
/Users/user/.rvm/gems/ruby-1.8.7-p302/gems/thinking-sphinx-1.4.4/lib/
thinking_sphinx/active_record/has_many_association.rb:7:in `search'
app/controllers/contacts_controller.rb:53:in `index'

Pat Allan

unread,
Jun 26, 2011, 3:45:37 AM6/26/11
to thinkin...@googlegroups.com
I'm afraid this is where we hit the limitations of Thinking Sphinx.

As an alternative work-around, why not fork TS and use your version in your Gemfile? That way you can change all the search methods to be ts_search, and saves you rewriting the bulk of your site?

--
Pat

Reply all
Reply to author
Forward
0 new messages