-->
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.  [ 1 post ] 
Author Message
 Post subject: Dynamic directories for indeces in Hibernate Search
PostPosted: Tue Feb 24, 2015 1:28 pm 
Newbie

Joined: Tue Feb 24, 2015 1:04 pm
Posts: 1
Hi,

in our application we have a special folder because of licences, database connection, etc for each user. Now we are implementing fulltext and query search using Hibernate Search technology, so we want multiple folders, where to store indeces, according to the user who uses the application. So we are trying to implement our own DirectoryProvider.

Our vision was that everytime somebody is searching for a text, the DirectoryProvider gives him a correct directory (the getDirectory method) where to search and also when he tryies to save updates to searched entites or save new entites. In simple words, the application should just operate with index files owned by this user in his folder.

Some code for better understanding:

Code:
public class MyDirectoryProvider implements DirectoryProvider<NIOFSDirectory> {

    private NIOFSDirectory tempFolder;

    @Override
    public void initialize(String s, Properties properties, BuildContext buildContext) {
        // temp directory needs to be initialized
        this.tempFolder = createTempDirectory(); // this method is not important
        this.initIndexFolder(this.tempFolder.getDirectory(), properties, buildContext);

        // all home directories need to be initialized
        Collection<Directory> directories = directoryService.getAll();
        directories.parallelStream().forEach(
                d -> this.initIndexFolder(
                        d.getLuceneDirectory().getDirectory(), properties, buildContext));
    }

    @Override
    public void start(DirectoryBasedIndexManager directoryBasedIndexManager) {
    }

    @Override
    public void stop() {
        this.getDirectory().close();
    }

    @Override
    public NIOFSDirectory getDirectory() {
        Directory directory = ContextHolder.getContext().getDirectory(); // not important, a way how to get the directory of current user
        // if the app just started (user context is not available)
        if (directory  == null) {
            return this.tempFolder;
        }
        else {
            return directory.getLuceneDirectory(); // returns the directory with lucene files with indeces
        }
    }

    // inits the folders with indeces
    private void initIndexFolder(File directory, Properties properties, BuildContext buildContext) {
        try {
            DirectoryProviderHelper.createFSIndex(directory, properties, buildContext.getServiceManager());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}


The problem is with the temp folder which is present because there is no one logged when the application starts. So we need some temp directory for Hibernate search to initialize properly. I correctly get the user's folder while searching the indeces for the fulltext query, but when I try to save my entity, the method getDirectory is not even called and the updates are saved in the temp directory. Is this a right way to do it and we just need more time to develop it, or should we rather implement some special sharding strategy, because this DirectoryProvider implementation has no sence?

Hibernate and Lucene versions are the newest available.

Thanks a lot for your replies


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

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.