Excellent article, thank you for the contribution, would you also mind adding it to our knowledge base http://www.seamframework.org/Documentation/KnowledgeBase so other developers can easily access it in the future?
Thank you! I added it to the external links section of the knowledge base.
I am a novice programmer in Seam field,and i always thank to the ones that share their knowledge,and you too.I pray for all of you.
It is my duty to thanks to the ones like you,because of this i post this message in this forum.
Thanks for article. I'm curious if it is possible to to combine full text search with domain model search. Lets say I have auction platform and want to search all offers with given search string and that are shipped from Malopolska region. Note my model associations (in brackets I put multiplicity):
Offer(*)-(1)Location Country(1)-(*)Region Region(1)-(*)Town
Location is superclass of Country, Region and Town.
The query should return offers that are associated with region Malopolska or all towns in this region.
@Bernard: I know it was long time ago but did you find a solution to combine full text with domain model search? I preferably want to use the framework classes like EntityQuery, but i'm unsure about how to mix EJBQL with Lucene Queries...
Thanks a lot for remembering ;-)
Hibernate Search in Actionand it seems, that you can combine full-text and domain model search to some extent, but not entirely. I see 3 solutions :
1) Map everything you want to search by into Lucene and do everything with full-text (HibernateSearch). You can map assocations as well but index grows.
2) Provide filter. There is such thing in HibernateSearch. It works fine if you want to i.e. filter out all censored or unpublished content (key point is that those attributes do not change with each query). It will be to costly to build filter for every query, since you would have to first fetch all records that do not match model criteria and apply them to the filter (which works on Lucene results).
3) Provide your own proxy. This is my idea but I consider it very weak. This is how it should work :
Do full-text search and get results create model query and add constraint to search among returned id's.
In my opinion (maybe i don't know about something) it would be very easy for HibernateSearch to provide mixed search, because this is how it works now:
1)fetch matching ids from Lucene (full-text search)
2)load entities from db by providing clause
where id in(?,?,?...).
So it seems to be a piece of cake to insert some more conditions in point 2, but I haven't found such possibility yet.
I've just found this on HibernateSearch FAQ:
This is not possible as there is no way to intersect the results from both queries without iterating on at least one of the results.
You may consider adding additional fields to the Lucene index and then look at the Filters in the reference documentation.
So it seems they are not going to follow my suggestion. Well, I agree that it could require lots of roundtrips i.e. : Fetch 10 items where name should be looked for by full-text search and category by model search (lets say hierarchical category search - include all subcategories).
Then proxy (HibernateSearch currently) would have to :
1) fetch 10 (or more) items from Lucene
2) execute model query within Lucene results
3) if there are less then 10 final results and lucene has more results then go to step 1
Well this can be very inefficient. Probably the best way is to map everything to Lucene.
Many thanks Bernard!
I didn't think it would be an easy and cost-free job anyway, but i wanted to be sure (i had the two-step and index solutions in my mind before too, but they are not that elegant, as you've stated). So if it is not too expensive to search all fields via Lucene regarding space and performance, i'll give it a try...