Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thinking Sphinx: Querying only specific fields in a models index

Lots of Thinking Sphinx questions from me lately. Here's another one:

In some of my searches I'd like to only query some of all the fields included in my index definition. I can't seem to find any on this, the nearest thing being limiting the global search to specific models.

So.. is it possible to query only a given subset of fields in an index?

like image 478
rogerkk Avatar asked Dec 12 '22 09:12

rogerkk


2 Answers

This is possible through Sphinx's extended match syntax:

Model.search "@(name,description) ruby pancakes", :match_mode => :extended

Where name and description are fields you're searching on, and 'ruby pancakes' is the search query.

like image 184
pat Avatar answered May 01 '23 06:05

pat


Now when Sphinx v3 is out, the documentation says that extended mode is turned on by default so you just need to do something like:

Model.search "@(name,description) ruby pancakes"
like image 41
NoDisplayName Avatar answered May 01 '23 06:05

NoDisplayName