在 rails 中使用 thinking-sphinx 创建搜索,仅搜索索引的某些属性
Creating a search with thinking-sphinx in rails with only certain attributes of the index searched for
我在 sphinx 中有一个这样的索引:
ThinkingSphinx::Index.define :publication, :with => :active_record do
indexes transcript.transcript_text, :as => :transcript
indexes taggings.tag.name, :as => :tags
end
我想进行忽略成绩单而只搜索标签的搜索。有什么方法可以构建搜索来做到这一点?
我认为在该索引上可能无法实现,因此我为此创建了一个新索引:
ThinkingSphinx::Index.define :publication, :name => 'tag_only', :with => :active_record do
indexes taggings.tag.name, :as => :tags
end
但是,我找不到任何关于如何在搜索中实际使用这样的命名索引的信息。我在哪里指定我想在这样的查询中使用 tag_only 索引:
Publication.search(terms, :with => with_conditions, :ranker => :matchany)
任何见解将不胜感激,谢谢!
据我了解,定义中的每个 indexes
都在基础 sphinx 索引中创建了一个 field
。
默认情况下,对索引的搜索查询会搜索所有字段。因此,在您的第一个示例中,对该索引的搜索将包括这两个字段。
在第二个索引上搜索只有一个字段,根据定义只会搜索该字段。所以不需要特定的特定领域。
... 要仅搜索特定索引中的一个(或其他子集)字段,可以直接使用 Sphinxes Extended 语法。
http://sphinxsearch.com/docs/current.html#extended-syntax
或者出现可以使用的条件
http://freelancing-gods.com/thinking-sphinx/searching.html#conditions
(必须映射到自动扩展查询:)
类似
Publication.search :conditions => {:tags => terms}, :ranker => :matchany
其中 :tags
是您在定义中对字段的称呼(抱歉不知道 ruby 语法是否完全正确。)
我在 sphinx 中有一个这样的索引:
ThinkingSphinx::Index.define :publication, :with => :active_record do
indexes transcript.transcript_text, :as => :transcript
indexes taggings.tag.name, :as => :tags
end
我想进行忽略成绩单而只搜索标签的搜索。有什么方法可以构建搜索来做到这一点?
我认为在该索引上可能无法实现,因此我为此创建了一个新索引:
ThinkingSphinx::Index.define :publication, :name => 'tag_only', :with => :active_record do
indexes taggings.tag.name, :as => :tags
end
但是,我找不到任何关于如何在搜索中实际使用这样的命名索引的信息。我在哪里指定我想在这样的查询中使用 tag_only 索引:
Publication.search(terms, :with => with_conditions, :ranker => :matchany)
任何见解将不胜感激,谢谢!
据我了解,定义中的每个 indexes
都在基础 sphinx 索引中创建了一个 field
。
默认情况下,对索引的搜索查询会搜索所有字段。因此,在您的第一个示例中,对该索引的搜索将包括这两个字段。
在第二个索引上搜索只有一个字段,根据定义只会搜索该字段。所以不需要特定的特定领域。
... 要仅搜索特定索引中的一个(或其他子集)字段,可以直接使用 Sphinxes Extended 语法。 http://sphinxsearch.com/docs/current.html#extended-syntax
或者出现可以使用的条件 http://freelancing-gods.com/thinking-sphinx/searching.html#conditions (必须映射到自动扩展查询:)
类似
Publication.search :conditions => {:tags => terms}, :ranker => :matchany
其中 :tags
是您在定义中对字段的称呼(抱歉不知道 ruby 语法是否完全正确。)