-->
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.  [ 7 posts ] 
Author Message
 Post subject: Dynamic Index Base and Index Name for Hibernate Search Shard
PostPosted: Wed Feb 10, 2010 1:21 am 
Newbie

Joined: Wed Nov 18, 2009 7:00 pm
Posts: 12
I have a requirement where I have a large number of shards for my index >200. I have a custom sharding strategy where I shard based on a defined key. I would like to have an indexbase for each key. e.g. key = 1; indexbase = /usr/lucene/indexes/sharddir_1. Also I would like to have my entities' index belong to the respective indexbase based off the key. e.g persons index = /usr/lucene/indexes/sharddir_1/persons_1. Is there a way to programmatically accomplish this, otherwise the config will become a maintenance nightmare.


Top
 Profile  
 
 Post subject: Re: Dynamic Index Base and Index Name for Hibernate Search Shard
PostPosted: Wed Feb 10, 2010 5:22 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hello,
To keep configuration simple you can manage it programmatically, that's a new feature since the latest beta of version 3.2:
Code:
http://in.relation.to/Bloggers/HibernateSearch32ProgrammaticMappingAPI


If you don't need to dynamically add shards but are ok with configuration-defined shards that solves your problems, but if you need to add indexes at runtime that's not currently possible: index management is quite heavy and so these services are started at SearchFactory initialization.

For an example, I am running a system having a different shard for each supported language (50 different languages), the configuration is defined programmatically using a for each loop on supported languages; but when we add support for a new language I have to redeploy the service; that doesn't very often.

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


Top
 Profile  
 
 Post subject: Re: Dynamic Index Base and Index Name for Hibernate Search Shard
PostPosted: Wed Feb 10, 2010 2:30 pm 
Newbie

Joined: Wed Nov 18, 2009 7:00 pm
Posts: 12
I cannot upgrade to the beta version due to deadline constraints. I was hoping that there's a way to intercept the configuration prior to initialization.


Top
 Profile  
 
 Post subject: Re: Dynamic Index Base and Index Name for Hibernate Search Shard
PostPosted: Wed Feb 10, 2010 7:47 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
you've luck, it's opensource so you have several options :)
You could "edit" the configuration programmatically before it's used for initialization, it's like a Properties object you can just add new key/values.
look into org.hibernate.search.event.FullTextIndexEventListener
Code:
public void initialize(Configuration cfg) {
   cfg.setProperty( propertyName, value ) //add all stuff you need
   searchFactoryImplementor = ContextHolder.getOrBuildSearchFactory( cfg );


You can create an extension of FullTextIndexEventListener, then disable auto-registration of the eventlistener and register your own.

With the suggestion above I'm assuming the container is deploying hibernate, but if you start it from you own code you can change the Configuration before starting Hibernate core.

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


Top
 Profile  
 
 Post subject: Re: Dynamic Index Base and Index Name for Hibernate Search Shard
PostPosted: Tue Feb 16, 2010 1:44 pm 
Newbie

Joined: Wed Nov 18, 2009 7:00 pm
Posts: 12
Thanks, Saanne!! It worked


Top
 Profile  
 
 Post subject: Re: Dynamic Index Base and Index Name for Hibernate Search Shard
PostPosted: Tue Feb 16, 2010 2:36 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
I'm glad you made it:)

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


Top
 Profile  
 
 Post subject: Re: Dynamic Index Base and Index Name for Hibernate Search Shard
PostPosted: Fri Feb 11, 2011 2:10 am 
Newbie

Joined: Fri Oct 15, 2010 2:31 am
Posts: 2
hello,

could you please help me to configure similar situation? I need to read index base location from database.
Problem is that in our project we are using automatic hibernate configuration (annotation 3.3.x) and so there is no hibernate configuration file - only persistence.xml. So, I have no experience with hibernate configuration at all. I do not know how and where to tell hibernate that I want to use my own FullTextIndexEventListener.
Code:
public class MyFullTextIndexEventListener extends FullTextIndexEventListener {
    @Override
    public void initialize(Configuration cfg) {
        // Read index location from database
        ConfigReader cr = ConfigReader.getInstance(Constants.hotlineParamReaderJNDI);
        String indexDirectory = cr.getStringValue(Constants.INDEX_LOCATION);
        cfg.setProperty("hibernate.search.default.indexBase", indexDirectory);
       
        searchFactoryImplementor = SearchFactoryImpl.getSearchFactory(cfg);
        String indexingStrategy = cfg.getProperties().getProperty(Environment.INDEXING_STRATEGY, "event");
        if ("event".equals(indexingStrategy)) {
            used = !searchFactoryImplementor.getDocumentBuilders().isEmpty();
        } else if ("manual".equals(indexingStrategy)) {
            used = false;
        } else {
            throw new SearchException(Environment.INDEXING_STRATEGY + " unknown: " + indexingStrategy);
        }
    }
}

Thanks in advance and have a nice day (-:
Jan

PS: I know that our environment is old. But hibernate-core could not be updated (glassfish2 has problems with JPA2.0) - so I was forced to choose old hibernate-search/lucene too.
hibernate 3.2.6 (hibernate-annotation 3.3.1) using JPA
hibernate-search 3.0.1
lucene 2.4.1
glassfish 2.1.1


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