views:

612

answers:

2

Official Lucene Feautures site states that lucene supports "multiple-index searching with merged results".

Is it possible to do this with hibernate search somehow?

My usecase: Aricle with Comments. I want to have two separate indices: one for articles and one for comments. I want to be able to find article also by match in one of comments. From user perspective, I want search that "looks" into article text and also its comments and returns list of articles. (I know I can implement this by storing all comments as fields inside article document, but I want to apply filters on search in comments.)

Is it even possible with native Lucene or I/m completely missing the point?

+1  A: 

It would be easier to give each article an ID. Then store the comments outside the articles but with a field that tells you what article a comment is on. Search both indexes (or the same index with different fields called "article" and "comment) and then merge on the article ID. This way you could set filters seperately on the results from the article query and the comment query.

Gandalf
+2  A: 

Your whole explanation seems vague. Hibernate Search seems like a good fit for your use case, provided that you have a proper domain model, meaning an article which is somehow linked to the comments, via a OneToMany association for example. If there is no relation between Article and Comment how would you know anyway to which article a Comment belongs?

Having such a domain model will solve your use case - being able to search in Articles and Comments, but return a list of Articles.

That said, it is possible to keep a separate Lucene index for Article and Comment. In fact, if you add @Indexed to each class, one index per class is created. However, the search becomes more complex.

I recommend to use @Indexed on Article, have a properly mapped relationship to Comment in Article and use @IndexedEmbedded on it.

If you want more hel you really have to post your domain model or provide more information about your requirements/usecases.

--Hardy

Hardy