pat / thinking-sphinx

Sphinx/Manticore plugin for ActiveRecord/Rails
http://freelancing-gods.com/thinking-sphinx
MIT License
1.63k stars 468 forks source link

Giving the search an array? #298

Closed gregwinn closed 12 years ago

gregwinn commented 12 years ago

Hello, I am working on a project that requires many search "terms" in one search so something like this:

search_terms = ["Term One", "Term2", "Another Term"]
Post.search search_terms

Is this possible and if not is there a better way to do this?

Thank you very much for any help!

pat commented 12 years ago

Hi Greg

It depends - what is the expected behaviour when there's more than one search term? Do you want records that match all terms? Or any?

Pat

On 27/10/2011, at 9:11 PM, Greg Winn wrote:

Hello, I am working on a project that requires many search "terms" in one search so something like this:

search_terms = ["Term One", "Term2", "Another Term"] Post.search search_terms

Is this possible and if not is there a better way to do this?

Thank you very much for any help!

Reply to this email directly or view it on GitHub: https://github.com/freelancing-god/thinking-sphinx/issues/298

gregwinn commented 12 years ago

Hey Pat, Any of the phrases given.

Thanks for the reply!!

pat commented 12 years ago

Hi Greg

That makes things a little tricky - you're going to have to do something like this: terms = ['alpha', 'beta gamma', 'delta'] Post.search "\"#{terms.join('" | "')}\"", :match_mode => :extended

This keeps each term together (instead of breaking them up into separate words), and inserts the OR separator between each one. The extended match mode is required for both quotes and OR pipes to work.

Give that a shot, let me know how you go.

Cheers

Pat

On 28/10/2011, at 7:10 PM, Greg Winn wrote:

Hey Pat, Any of the phrases given.

Thanks for the reply!!

Reply to this email directly or view it on GitHub: https://github.com/freelancing-god/thinking-sphinx/issues/298#issuecomment-2559272

gregwinn commented 12 years ago

Pat, Thank you very much! This did work!

Thank you very much!!!! Greg