我正在尝试实现基于 Solr 的消息线程搜索。每条消息可以有许多回复(回复只能是一个级别的深度。)。我想检索内容与搜索键匹配的父消息或与搜索键匹配的回复。
例如:
Hello Jack
Hello Janice
How are you?
..
I am Janice
How are you?
Welcome to the Jungle
Nothing better to do.
搜索Janice
应该返回以下结果集:
Hello Jack # one of the child messages matches the key word
I am Janice # parent message matched the keyword)
我的模型如下:
class Message < ActiveRecord::Base
belongs_to :parent, :class_name => "Message"
has_many :replies, :class_name => "Message", :foreign_key => :parent_id
# content
searchable do
text :content
integer :parent_id
end
end
用于指定嵌套子查询的 DSL 语法是什么?
编辑 1
我考虑创建一个复合文本索引字段来保存所有索引。但是这种方法在我的场景中是不可行的,因为我必须确保回复符合某些附加标准。
class Message < ActiveRecord::Base
belongs_to :parent, :class_name => "Message"
has_many :replies, :class_name => "Message", :foreign_key => :parent_id
belongs_to :category
# content
searchable do
text :content
integer :category_id
integer :parent_id
end
end
在上述模型中,我想将文本搜索限制为给定类别。