Example usage for org.apache.lucene.store RAMDirectory RAMDirectory

List of usage examples for org.apache.lucene.store RAMDirectory RAMDirectory

Introduction

In this page you can find the example usage for org.apache.lucene.store RAMDirectory RAMDirectory.

Prototype

public RAMDirectory(FSDirectory dir, IOContext context) throws IOException 

Source Link

Document

Creates a new RAMDirectory instance from a different Directory implementation.

Usage

From source file:com.impetus.kundera.index.LuceneIndexer.java

License:Apache License

/**
 * Instantiates a new lucene indexer.//from   w  w w . ja  v a  2s .c o  m
 * 
 * @param analyzer
 *            the analyzer
 * @param lucDirPath
 *            the luc dir path
 */
private LuceneIndexer(String lucDirPath) {
    try {
        luceneDirPath = lucDirPath;
        File file = new File(luceneDirPath);
        if (file.exists()) {
            FSDirectory sourceDir = FSDirectory.open(getIndexDirectory().toPath());

            // TODO initialize context.
            index = new RAMDirectory(sourceDir, IOContext.DEFAULT);
        } else {
            index = new RAMDirectory();
        }
        /*
         * FSDirectory.open(getIndexDirectory( ))
         */
        // isInitialized
        /* writer */
        IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer);
        LogDocMergePolicy logDocMergePolicy = new LogDocMergePolicy();
        logDocMergePolicy.setMergeFactor(1000);
        indexWriterConfig.setMergePolicy(logDocMergePolicy);
        w = new IndexWriter(index, indexWriterConfig);
        w.getConfig().setRAMBufferSizeMB(32);
    } catch (Exception e) {
        log.error("Error while instantiating LuceneIndexer, Caused by :.", e);
        throw new LuceneIndexingException(e);
    }
}

From source file:de.citec.sc.query.AnchorRetriever.java

private void initIndexDirectory(boolean loadToMemory) {
    try {/*from  w  w w.jav a 2 s  .  c  om*/
        String path = directory + "/" + this.indexPath + "/";
        analyzer = new StandardAnalyzer();
        if (loadToMemory) {
            indexDirectory = new RAMDirectory(FSDirectory.open(Paths.get(path)), IOContext.DEFAULT);
        } else {
            indexDirectory = FSDirectory.open(Paths.get(path));
        }

    } catch (Exception e) {
        System.err.println("Problem with initializing InstanceQueryProcessor\n" + e.getMessage());
    }
}

From source file:de.citec.sc.query.ClassRetriever.java

private void initIndexDirectory(boolean loadToMemory) {
    try {//from   w  w  w  . j  a  v a2  s .  c  om
        String pathEN = directory + "/en/" + this.indexPath + "/";
        String pathDE = directory + "/de/" + this.indexPath + "/";
        String pathES = directory + "/es/" + this.indexPath + "/";
        analyzer = new StandardAnalyzer();
        if (loadToMemory) {
            indexDirectoryEN = new RAMDirectory(FSDirectory.open(Paths.get(pathEN)), IOContext.DEFAULT);
            indexDirectoryDE = new RAMDirectory(FSDirectory.open(Paths.get(pathDE)), IOContext.DEFAULT);
            indexDirectoryES = new RAMDirectory(FSDirectory.open(Paths.get(pathES)), IOContext.DEFAULT);
        } else {
            indexDirectoryEN = FSDirectory.open(Paths.get(pathEN));
            indexDirectoryDE = FSDirectory.open(Paths.get(pathDE));
            indexDirectoryES = FSDirectory.open(Paths.get(pathES));
        }

    } catch (Exception e) {
        System.err.println("Problem with initializing InstanceQueryProcessor\n" + e.getMessage());
    }
}

From source file:de.citec.sc.query.DBpediaRetriever.java

private void initIndexDirectory(boolean loadToMemory) {
    try {/*  w  ww .  j  a  va 2  s  . co m*/
        String ontologyPredicatePath = directory + "/" + this.ontologyPredicateIndexPath + "/";
        String propertyPredicatePath = directory + "/" + this.propertyPredicateIndexPath + "/";
        String classPath = directory + "/" + this.classIndexPath + "/";
        String instancePath = directory + "/" + this.instancesIndexPath + "/";

        analyzer = new StandardAnalyzer();
        if (loadToMemory) {
            ontologyPredicateIndexDirectory = new RAMDirectory(
                    FSDirectory.open(Paths.get(ontologyPredicatePath)), IOContext.DEFAULT);
            propertyPredicateIndexDirectory = new RAMDirectory(
                    FSDirectory.open(Paths.get(propertyPredicatePath)), IOContext.DEFAULT);
            classIndexDirectory = new RAMDirectory(FSDirectory.open(Paths.get(classPath)), IOContext.DEFAULT);
            instanceIndexDirectory = new RAMDirectory(FSDirectory.open(Paths.get(instancePath)),
                    IOContext.DEFAULT);
        } else {
            ontologyPredicateIndexDirectory = FSDirectory.open(Paths.get(ontologyPredicatePath));
            propertyPredicateIndexDirectory = FSDirectory.open(Paths.get(propertyPredicatePath));
            classIndexDirectory = FSDirectory.open(Paths.get(classPath));
            instanceIndexDirectory = FSDirectory.open(Paths.get(instancePath));
        }

    } catch (Exception e) {
        System.err.println("Problem with initializing InstanceQueryProcessor\n" + e.getMessage());
    }
}

From source file:de.citec.sc.query.MATOLLRetriever.java

private void initIndexDirectory(boolean loadToMemory) {
    try {//from w w  w . ja  v a  2  s .com
        String pathClassEN = directory + "/en/" + this.indexPath1 + "/";
        String pathPredicateEN = directory + "/en/" + this.indexPath2 + "/";

        String pathClassDE = directory + "/de/" + this.indexPath1 + "/";
        String pathPredicateDE = directory + "/de/" + this.indexPath2 + "/";

        String pathClassES = directory + "/es/" + this.indexPath1 + "/";
        String pathPredicateES = directory + "/es/" + this.indexPath2 + "/";

        analyzer = new StandardAnalyzer();

        if (loadToMemory) {
            indexDirectoryClassDirEN = new RAMDirectory(FSDirectory.open(Paths.get(pathClassEN)),
                    IOContext.DEFAULT);
            indexDirectoryPredicateDirEN = new RAMDirectory(FSDirectory.open(Paths.get(pathPredicateEN)),
                    IOContext.DEFAULT);

            indexDirectoryClassDirDE = new RAMDirectory(FSDirectory.open(Paths.get(pathClassDE)),
                    IOContext.DEFAULT);
            indexDirectoryPredicateDirDE = new RAMDirectory(FSDirectory.open(Paths.get(pathPredicateDE)),
                    IOContext.DEFAULT);

            indexDirectoryClassDirES = new RAMDirectory(FSDirectory.open(Paths.get(pathClassES)),
                    IOContext.DEFAULT);
            indexDirectoryPredicateDirES = new RAMDirectory(FSDirectory.open(Paths.get(pathPredicateES)),
                    IOContext.DEFAULT);
        } else {
            indexDirectoryClassDirEN = FSDirectory.open(Paths.get(pathClassEN));
            indexDirectoryPredicateDirEN = FSDirectory.open(Paths.get(pathPredicateEN));

            indexDirectoryClassDirDE = FSDirectory.open(Paths.get(pathClassDE));
            indexDirectoryPredicateDirDE = FSDirectory.open(Paths.get(pathPredicateDE));

            indexDirectoryClassDirES = FSDirectory.open(Paths.get(pathClassES));
            indexDirectoryPredicateDirES = FSDirectory.open(Paths.get(pathPredicateES));
        }

    } catch (Exception e) {
        System.err.println("Problem with initializing InstanceQueryProcessor\n" + e.getMessage());
    }
}

From source file:de.citec.sc.query.ResourceRetriever.java

private void initIndexDirectory(boolean loadToMemory) {
    try {//from   ww w . j a  v  a  2  s  . c o  m
        String pathEN = directory + "/en/" + this.indexPath + "/";
        String pathDE = directory + "/de/" + this.indexPath + "/";
        String pathES = directory + "/es/" + this.indexPath + "/";

        analyzer = new StandardAnalyzer();
        if (loadToMemory) {
            indexDirectoryEN = new RAMDirectory(FSDirectory.open(Paths.get(pathEN)), IOContext.DEFAULT);
            indexDirectoryDE = new RAMDirectory(FSDirectory.open(Paths.get(pathDE)), IOContext.DEFAULT);
            indexDirectoryES = new RAMDirectory(FSDirectory.open(Paths.get(pathES)), IOContext.DEFAULT);
        } else {
            indexDirectoryEN = FSDirectory.open(Paths.get(pathEN));
            indexDirectoryDE = FSDirectory.open(Paths.get(pathDE));
            indexDirectoryES = FSDirectory.open(Paths.get(pathES));
        }

    } catch (Exception e) {
        System.err.println("Problem with initializing InstanceQueryProcessor\n" + e.getMessage());
    }
}

From source file:de.uni_koeln.spinfo.maalr.lucene.core.DictionaryLoader.java

License:Apache License

private synchronized void loadIndex() throws NoIndexAvailableException {
    if (searcher == null) {
        try {//ww w .  java  2 s.  c  o m
            logger.info("Loading index from directory " + environment.getLuceneIndexDir().getAbsolutePath());
            NIOFSDirectory directory = new NIOFSDirectory(environment.getLuceneIndexDir());
            ram = new RAMDirectory(directory, new IOContext());
            reader = DirectoryReader.open(ram);
            searcher = new IndexSearcher(reader);
            searcher.setSimilarity(new SimilarityBase() {

                @Override
                public String toString() {
                    return "Constant Similarity";
                }

                @Override
                protected float score(BasicStats stats, float freq, float docLen) {
                    return stats.getTotalBoost();
                }

            });
            directory.close();
            logger.info("Index loaded.");
        } catch (IOException e) {
            throw new NoIndexAvailableException("Failed to load index", e);
        }
    }
}

From source file:edu.illinois.cs.cogcomp.bigdata.lucene.Lucene.java

License:Open Source License

public static IndexReader ramReader(String pathToIndex) throws IOException {
    return DirectoryReader.open(new RAMDirectory(new MMapDirectory(Paths.get(pathToIndex)), IOContext.READ));
}

From source file:in.cdac.medinfo.csnotk.csnolib.agents.LuceneSearchAgent.java

License:Apache License

/**
 * /*  w ww.  j  a va 2  s  .c om*/
 * @return indexDirectory
 * @throws IOException
 */
private static Directory getIndexDirectorytoRead() throws IOException {
    if (indexDirectory == null) {
        synchronized (mutex) {
            Properties properties = null;
            try {
                properties = PropertyReader.loadSystemProperties();
            } catch (IOException e) {
                //Get the Stack trace and form the exception message.
                StackTraceElement arrStackTraceElement[];
                arrStackTraceElement = e.getStackTrace();
                String strMessage = e.getClass() + Constants.NEW_LINE + Constants.CLASS_NAME
                        + arrStackTraceElement[0].getClassName() + Constants.NEW_LINE + Constants.METHOD_NAME
                        + arrStackTraceElement[0].getMethodName() + Constants.NEW_LINE + Constants.LINE_NUMBER
                        + arrStackTraceElement[0].getLineNumber() + Constants.NEW_LINE
                        + Constants.MESSAGE_DESCRIPTION + e.getMessage();
                //Log the Exception
                CSNOLogger.logException(strMessage);
            }
            //public RAMDirectory(Directory dir,IOContext context) throws IOException
            //Creates a new RAMDirectory instance from a different Directory implementation. This can be used to 
            //load a disk-based index into memory.

            //Warning: This class is not intended to work with huge indexes. Everything beyond several hundred 
            //megabytes will waste resources (GC cycles), because it uses an internal buffer size of 1024 bytes,
            //producing millions of byte[1024] arrays. This class is optimized for small memory-resident indexes. 
            //It also has bad concurrency on multithreaded environments.
            //Note that the resulting RAMDirectory instance is fully independent from the original Directory (it is a complete copy).
            //Any subsequent changes to the original Directory will not be visible in the RAMDirectory instance.
            indexDirectory = new RAMDirectory(
                    FSDirectory.open(new File(properties.getProperty(Constants.INDEX_DIR))),
                    IOContext.READONCE);
        }
    }
    return indexDirectory;
}

From source file:io.datalayer.lucene.helper.AosUtil.java

License:Apache License

public void dirCopy() throws Exception {
    Directory otherDir = null;//w ww  .j av  a2  s  .c  o m
    Directory ramDir = new RAMDirectory(otherDir, new IOContext());
}