恕我直言,您应该将帖子和评论存储在不同的文档上。您可以将帖子 ID 放在评论文档中,这样您就可以知道哪个帖子拥有每条评论。
我的字段建议是:
id - if you have the risk of getting the same id for a comment and a post, you should use some kind of prefix at the document id. In this case, you have another field to store the original id
_type (post or comment) -
post_id - this field will store the post id, a comment is child. It will be empty at the post documents
title (empty for comments, maybe?)
content - the actual text a comment or post has
text - the field that contains all text you want to query in a document, via copyfield (only if you don't want to boost the individual fields)
<any other fields you may need>
您可以简单地执行 ?q=text:"foo" 来查询您的帖子或评论,您将检索与 foo 匹配的所有文档。然后您可以查询返回的 post_id,或者您可以尝试某种连接。看看http://wiki.apache.org/solr/Join。你会做类似?q=({join from=post_id to=id}text:"foo") (+text:foo +_type:post)