如何基于在狮身人面像搜索
问题描述:
我有一个多态关联一张纸条模型,就像下面如何基于在狮身人面像搜索
incident has one symptom -> (note model)
incident has many comments -> (note model)
和
我愿做中缀条件加缀和前缀索引嵌套模型索引与笔记型“症状”的字条,并希望做前缀索引与类型的纪录“注释”
我试过在狮身人面像索引下面的代码
ThinkingSphinx::Index.define(:incident, DEFAULT_INDEX_OPTIONS.merge(name: "incident_prefix"), &Searchable.beetilable_index('Incident', index_count: incident_index_count, index_id: i) {
set_property :min_infix_length => 3
indexes notes.note, :as => :notes, :source => :query
notes.where(note_type: "Symptom")
}
ThinkingSphinx::Index.define(:incident, DEFAULT_INDEX_OPTIONS.merge(name: "incident_infix"), &Searchable.beetilable_index('Incident', index_count: incident_index_count, index_id: i) {
set_property :min_prefix_length => 3
indexes notes.note, :as => :notes, :source => :query
notes.where.not(note_type: "Symptom")
}
上面的代码只是使用INFIX选项进行索引,而忽略了PREFIX之一。我猜我的病情有问题,有人能让我知道如何实现这一目标吗?
答
恐怕你不能在索引定义中使用Arel/ActiveRecord查询方法来构建关联 - 你只能使用关联和列。
如果您只需要某些类型的笔记,然后在这里最好的方法是创建应用了这些过滤器的关联,然后引用索引的关联关系:
# in the model
has_many :symptom_notes,
lambda { where(:note_type => "Symptom") },
:class_name => "Note"
# in the index:
indexes symptom_notes.note, :as => :notes