开发者

Thinking Sphinx - Already have a search method in the model?

I'd like to use Thinking Sphinx, but I keep having problems because I have a very large rails project and the search method is used in many of my models. These already existing search methods conflict with Thinking Sphinx's search method. Is there any way around this?

I'm talking thousands of lines of code I would have to change if I had to change my search method to some开发者_如何学编程thing else. I can't seem to find a way to change the default search method in Thinking Sphinx though either.

Thanks.


Just answered this on the TS list, but happy to answer here as well :)

There isn't any inbuilt way to do this, but in theory it could be possible. Firstly - Thinking Sphinx adds the class-level search method when you call define_index on a model - so, if you define your own search method after that, it'll overwrite the Thinking Sphinx version.

This means you could just define a new method that does the same thing - here's the code for Model.search:

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

Which you could easily rename to something else:

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

The one possible catch with this is that Thinking Sphinx may have expectations internally on the search method existing and behaving as normal. I'm not sure - but give this a spin and see how you go!

Update:

As it turns out, the above suggestion doesn't cover all situations and it's still buggy. So, I think the fallback solution is to fork Thinking Sphinx, change the method names, and use your version instead of the canonical one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜