-->
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.  [ 6 posts ] 
Author Message
 Post subject: Search from DB??
PostPosted: Wed Feb 24, 2010 3:10 am 
Newbie

Joined: Tue Feb 23, 2010 10:46 pm
Posts: 17
Hi,

I was doing some testing on Hibernate Search. I created some records through the system and they are successfully indexed. I expect to do a manual re-indexing after I ve modified the database manually that the change are not captured through the system..

However, after I ve made changes directly to the database, my search results reflects the newly updated records. Thus, can i say that Hibernate Search search the database instead of the indexed files? Can i enforce the Hibernate Search to search the indexed files only?

All columns in my entity are indexed and referenced the following example for search:

org.apache.lucene.queryParser.QueryParser parser = new QueryParser("title", new SimpleAnalyzer());
org.apache.lucene.search.Query luceneQuery = parser.parse( "title:sky Or title_stemmed:diamond" );
org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery, Song.class );
List result = fullTextQuery.list(); //return a list of managed objects


Top
 Profile  
 
 Post subject: Re: Search from DB??
PostPosted: Wed Feb 24, 2010 10:43 am 
Hibernate Team
Hibernate Team

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

I guess what you are seeing is that the search results reflect the latest state of the entities in the db. This does not mean that this changes are searchable. Generally, Hibernate Search will execute a search against the Lucene index to determine the ids for the matching entities. Then, these entities are loaded from the database. If they have changed in the db you might be seeing updated values. If as in your case the changes were made bypassing Hibernate you should not be able to find entities using queries which would only match the applied changes.

You could use projection (see online docs) to retrieve the actual indexed values, but in this case you don't get managed entities back, but rather object arrays and you might have to hydrate entities/objects yourself, eg by using a result set mapper.

I hope this help.

--Hardy


Top
 Profile  
 
 Post subject: Re: Search from DB??
PostPosted: Wed Feb 24, 2010 9:50 pm 
Newbie

Joined: Tue Feb 23, 2010 10:46 pm
Posts: 17
Hi,
Yes, I cannot find entities using queries which only match applied changes.

However, can I enforce Hibernate search to only search the indexed files instead of accessing the database again after obtaining the ids? Is there any configuration to enforce this rule?

thanks!!


Top
 Profile  
 
 Post subject: Re: Search from DB??
PostPosted: Thu Feb 25, 2010 4:14 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
sure, have a look into Projections: http://docs.jboss.org/hibernate/stable/search/reference/en/html_single/#projections

of course that's only going to show the data as last indexed, so it's a tradeoff in consistent data / performance: make sure to load the entities from DB before important operations; i.e. projections is meant to be used for previewing the search results, like in the text snippets you show in a search results table, but then it's recommended to load the entity from DB when a row is selected.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Search from DB??
PostPosted: Thu Feb 25, 2010 5:08 am 
Newbie

Joined: Tue Feb 23, 2010 10:46 pm
Posts: 17
Is projection the only solution? as mentioned that projection would get back the managed entities.


Top
 Profile  
 
 Post subject: Re: Search from DB??
PostPosted: Thu Feb 25, 2010 5:46 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
we call Projection the operation of extracting data from the index directly; if you also ask for objects you'll also hit the database, but if you ask for projected data only you won't hit the database.
Hint: enable the hibernate query log to verify when it does query the database.

Quote:
Is projection the only solution?

Besides the projection api provided by Search, you can do whatever you want by using the direct access to the IndexReader:
http://docs.jboss.org/hibernate/stable/search/reference/en/html_single/#d0e3539

but whatever you do with the reader directly will be quite similar than the projection api, or would you have some idea for improvements?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.