-->
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.  [ 5 posts ] 
Author Message
 Post subject: Native Lucene without using Session
PostPosted: Tue Nov 30, 2010 2:27 pm 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Hi All

Due to my usecase I have the need to access the native Lucene APIs. Is it safe to access the directory without using a hibernate session? For example in order to get an index reader at present I need to get a FullTextSession which wraps an Hibernate Session and then make my way to the Directory. Is it ok for me to create a IndexReader with just using the directory path and then closing the IndexReader after I've used it?

Thanks
Amin


Top
 Profile  
 
 Post subject: Re: Native Lucene without using Session
PostPosted: Wed Dec 01, 2010 9:25 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi Amin,
yes provided you use the IndexReader in read only mode it would be safe, but you actually get the same object you would from the FullTextSession, but this one as some benefits:

  • in case you enable sharding, you would still receive the correct one or a multireader wrapping the correct ones
  • Search manages the IndexReader to provide very efficient reopening strategies, it won't be as fast just opening one yourself
  • opening a Hibernate Session doesn't open a database connection until you need it, so it's a cheap operation
  • first search of Lucene index on a new reader will be slower as the internal fieldcaches must be filled. using the Search provided reader this might be pooled and so it might have the caches filled in already
  • you don't need to configure externally where these directories are
  • you would have an hard time getting the reference to any non-fs directory, so it would be hard to try for example the new Infinispan based index

you have other reasons to open one yourself?
also you actually only need a reference to the SearchFactory, you could retrieve this once and keep the reference without opening a Session everytime you need (although that's not slow at all).

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


Top
 Profile  
 
 Post subject: Re: Native Lucene without using Session
PostPosted: Wed Dec 01, 2010 2:51 pm 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Hi Sanne

Thanks for your detailed reply. I really like the idea of storing the reference of the SearchFactory on initialisation and re use that as I normally would. It makes sense to use HSearch to get to the underlying index. I presume there will be no side effect (not getting up to date data) if I store the reference of the SearchFactory.

The main reason for asking this is that we started to notice we were running out of db connections, although this might be unrelated to search, I have more control of the search code so i'd like to take some defensive measures.

Amin


Top
 Profile  
 
 Post subject: Re: Native Lucene without using Session
PostPosted: Thu Dec 02, 2010 6:56 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
that should be unrelated, actually using Search more should be an effective strategy to reduce the need for database connections.
Check for leaks in your application or connection pool, if you deploy it on JBoss you get warnings logged about unclosed connections.

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


Top
 Profile  
 
 Post subject: Re: Native Lucene without using Session
PostPosted: Thu Dec 02, 2010 10:36 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Hi Sanne

We found the culprit, it turns out we have a custom datasource factory which is built using Spring, however there is a fundamental bug in the code that is the root cause.

Thanks
Amin


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.