メッセージスレッドのSolrベースの検索を実装しようとしています。各メッセージには多くの返信を含めることができます(返信の深さは1レベルのみです)。検索キーに一致するコンテンツを含む親メッセージを取得するか、検索キーに一致する返信を取得したい。
例えば:
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
上記のモデルでは、テキスト検索を特定のカテゴリに制限したいと思います。