-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Questions on indexing
PostPosted: Fri Feb 06, 2009 9:40 am 
Beginner
Beginner

Joined: Tue Feb 03, 2009 12:29 pm
Posts: 49
I read that Hibernate search does hit the DB when we search for indexed entities and that this can be avoided only when projections are used. I had the following questions based on this.

1. If Hibernate search does hit the DB for every search, then how does it give better performance than a normal DB query?

2. If I use Store.YES for the indexed field, the data is available in the index. Even then why does Hibernate hit the DB when searching for it?

3. Suppose my indexed entity has @IndexedEmbedded annotations for including related entities. If an indexed field changes in one of these related index. Will the whole lucene index be updated or only the section for this field be updated?

4. Suppose I index a collection of entities. Will the automatic updation of indexes work even if I retrieve data using projections?

Thanks in advance.

-Seema


Top
 Profile  
 
 Post subject: Re: Questions on indexing
PostPosted: Sat Feb 07, 2009 6:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

Quote:
1. If Hibernate search does hit the DB for every search, then how does it give better performance than a normal DB query?

Hibernate Search does not search against the database. Per default Search will execute the search against the Lucene index to determine the entity ids which match the search query. Then it will load this entities from the database using plain old Hibernate. The advantage of course is that you always work with manages objects. The benefit of Lucene is that it is a freetext search engine. It offers functionality like wildcard search, fuzzy search, proximity search, etc. All this is not available to you in a normal DB query. The LIKE queries you would use in a direct DB query are just not as powerful and perform not as well as Lucene queries.
If you don't need fulltext search capabilities you can of course use HQL instead. In fact nothing stops you using a mixed apporach - where you use HQL for 'traditional' queries and Hibernate Search for fulltext queries.

Quote:
2. If I use Store.YES for the indexed field, the data is available in the index. Even then why does Hibernate hit the DB when searching for it?

Because the aim is to work with managed entities. The developer does not have to shift his programming paradigm.

Quote:
3. Suppose my indexed entity has @IndexedEmbedded annotations for including related entities. If an indexed field changes in one of these related index. Will the whole lucene index be updated or only the section for this field be updated?

Lucene Documents can not be updated. Effectively the document gets deleted and reinserted. That's just the way Lucene works.

Quote:
4. Suppose I index a collection of entities. Will the automatic updation of indexes work even if I retrieve data using projections?

Yes.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 07, 2009 9:53 am 
Beginner
Beginner

Joined: Tue Feb 03, 2009 12:29 pm
Posts: 49
Thanks for the responses. I understand that to get benefit from using Store.YES, I must use projections instead of this approach. I went through the documentation about projections, but few things were not clear.

Quote:
1. FullTextQuery.THIS: returns the intialized and managed entity (as a non projected query would have done)

- If I use this option with projection, will it cause a DB hit since I'm getting back a managed entity. If yes, then what is the difference between this and the no-projection approach?

Quote:
2. # you can only project simple properties of the indexed entity or its embedded associations. This means you cannot project a whole embedded entity.
# projection does not work on collections or maps which are indexed via @IndexedEmbedded


- Does this mean that if my indexed entity or its associated entity(@IndexedEmbedded) has a collection valued property, I cannot retrieve it?

Thanks,
Seema


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 07, 2009 5:22 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Quote:
- If I use this option with projection, will it cause a DB hit since I'm getting back a managed entity. If yes, then what is the difference between this and the no-projection approach?

If you just use FullTextQuery.THIS there is effectively no real difference to running a 'normal' Search query. It could make sense to use it in case you also want access to BOOST or SCORE. Projecting on THIS will not save you the db hit (even though with proper Hibernate caching your object might be in the second level cache)

Quote:
- Does this mean that if my indexed entity or its associated entity(@IndexedEmbedded) has a collection valued property, I cannot retrieve it?

You can project on simple properties, but you won't get back a whole collection.

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.