开发者

Thinking Sphinx: Querying only specific fields in a models index

开发者 https://www.devze.com 2023-04-01 10:57 出处:网络
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

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?


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.


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"


Not sure about Thinking Sphinx but I know if you hit Sphinx directly via SphinxQL than you can specify the fields you want to match against.

I'd be surprised if TS didnt expose this functionality to you...


I haven't worked with TS for a while, but I remember you could create separate index which includes subset of fields you use on your main index. I don't think Sphinx distinguish fields you use to build index, because that's why you use full-text search server - to search content on multiple fields at once.

So just check how to build new index with other fields and how to use this new index instead of default.

0

精彩评论

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