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

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

Introduction

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

Prototype

public MMapDirectory(Path path) throws IOException 

Source Link

Document

Create a new MMapDirectory for the named location and FSLockFactory#getDefault() .

Usage

From source file:biospectra.classify.Classifier.java

License:Apache License

private void initialize(File indexPath, int kmerSize, int kmerSkips, boolean minStrandKmer,
        double minShouldMatch, QueryGenerationAlgorithm queryGenerationAlgorithm, Similarity similarity)
        throws Exception {
    if (!indexPath.exists() || !indexPath.isDirectory()) {
        throw new IllegalArgumentException("indexPath is not a directory or does not exist");
    }/* w  w w  . ja  v  a 2 s .c o m*/

    this.indexPath = indexPath;
    this.kmerSize = kmerSize;
    this.kmerSkips = kmerSkips;
    this.minStrandKmer = minStrandKmer;
    this.queryAnalyzer = new KmerQueryAnalyzer(this.kmerSize, this.kmerSkips, this.minStrandKmer);
    Directory dir = new MMapDirectory(this.indexPath.toPath());
    this.indexReader = DirectoryReader.open(dir);
    this.indexSearcher = new IndexSearcher(this.indexReader);
    if (similarity != null) {
        this.indexSearcher.setSimilarity(similarity);
    }
    this.minShouldMatch = minShouldMatch;
    this.queryGenerationAlgorithm = queryGenerationAlgorithm;

    BooleanQuery.setMaxClauseCount(10000);
}

From source file:biospectra.index.Indexer.java

License:Apache License

private void initialize(File indexPath, int kmerSize, boolean minStrandKmer, Similarity similarity,
        int workerThreads, int ramBufferSize) throws Exception {
    if (!indexPath.exists()) {
        indexPath.mkdirs();//ww w  .  j  ava  2 s  .c o  m
    }

    if (indexPath.exists()) {
        cleanUpDirectory(indexPath);
    }

    this.indexPath = indexPath;
    this.minStrandKmer = minStrandKmer;
    this.analyzer = new KmerIndexAnalyzer(kmerSize, minStrandKmer);
    Directory dir = new MMapDirectory(this.indexPath.toPath());
    IndexWriterConfig config = new IndexWriterConfig(this.analyzer);
    if (similarity != null) {
        config.setSimilarity(similarity);
    }

    this.workerThreads = workerThreads;

    if (ramBufferSize > 0) {
        config.setRAMBufferSizeMB(ramBufferSize);
    }

    config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
    this.indexWriter = new IndexWriter(dir, config);

    this.executor = new BlockingExecutor(this.workerThreads, this.workerThreads * 2);

    for (int i = 0; i < this.workerThreads; i++) {
        Document doc = new Document();
        Field filenameField = new StringField(IndexConstants.FIELD_FILENAME, "", Field.Store.YES);
        Field headerField = new StringField(IndexConstants.FIELD_HEADER, "", Field.Store.YES);
        Field sequenceDirectionField = new StringField(IndexConstants.FIELD_SEQUENCE_DIRECTION, "",
                Field.Store.YES);
        Field taxonTreeField = new StringField(IndexConstants.FIELD_TAXONOMY_TREE, "", Field.Store.YES);
        Field sequenceField = new TextField(IndexConstants.FIELD_SEQUENCE, "", Field.Store.NO);

        doc.add(filenameField);
        doc.add(headerField);
        doc.add(sequenceDirectionField);
        doc.add(taxonTreeField);
        doc.add(sequenceField);

        this.freeQueue.offer(doc);
    }
}

From source file:biospectra.utils.IndexUtil.java

License:Apache License

private void initialize(File indexPath) throws Exception {
    if (indexPath == null) {
        throw new IllegalArgumentException("indexPath is null");
    }//from  w  w  w.j  a va 2  s . c o  m

    this.indexPath = indexPath;
    Directory dir = new MMapDirectory(this.indexPath.toPath());
    this.indexReader = DirectoryReader.open(dir);
}

From source file:br.bireme.ngrams.CompareResults.java

private static void compare(final String resultFile, final String indexPath, final String outputFile,
        final String encoding) throws IOException {
    assert resultFile != null;
    assert indexPath != null;
    assert outputFile != null;
    assert encoding != null;

    try (DirectoryReader ireader = DirectoryReader.open(new MMapDirectory(new File(indexPath).toPath()))) {
        final IndexSearcher isearcher = new IndexSearcher(ireader);

        try (BufferedReader breader = Files.newBufferedReader(new File(resultFile).toPath(),
                Charset.forName(encoding));
                BufferedWriter bwriter = Files.newBufferedWriter(new File(outputFile).toPath(),
                        Charset.forName(encoding))) {
            boolean first = true; // first line

            while (true) {
                final String line = breader.readLine();
                if (line == null)
                    break;
                if (first) {
                    first = false; // drop header line (first)
                } else {
                    final String line2 = line.trim();
                    if (!line2.isEmpty()) {
                        final String[] split = line2.split("\\|");
                        checkDocs(split[1], split[2], split[3], isearcher, bwriter);
                    }/*from  w  w w .  j a  va 2 s . co  m*/
                }
            }
        }
    }
}

From source file:br.bireme.ngrams.NGIndex.java

private IndexSearcher getIndexSearcher(final String indexPath) throws IOException {

    final DirectoryReader ireader = DirectoryReader.open(
            //FSDirectory.open(new File(indexPath).toPath()));
            new MMapDirectory(new File(indexPath).toPath()));
    //new RAMDirectory(FSDirectory.open(new File(indexPath).toPath()), IOContext.DEFAULT));
    //new RAMDirectory(FSDirectory.open(new File(indexPath).toPath()), IOContext.READONCE));

    return new IndexSearcher(ireader);
}

From source file:ca.ualberta.entitylinking.common.indexing.AliasLuceneIndex.java

License:Open Source License

public void initWriter(String dirLoc) {
    Directory dir = null;/*  w w w .  j av  a  2 s. c om*/
    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_34, analyzer);

    try {
        dir = new MMapDirectory(new File(dirLoc));
        writer = new IndexWriter(dir, conf);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ca.ualberta.entitylinking.common.indexing.AliasLuceneIndex.java

License:Open Source License

@SuppressWarnings("resource")
public static boolean exists(String diskDir) {
    Directory dir = null;//from  ww  w  .  j  a  v a2 s  . c om

    try {
        dir = new RAMDirectory(new MMapDirectory(new File(diskDir)));
        if (!IndexReader.indexExists(dir))
            return false;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    return true;
}

From source file:ca.ualberta.entitylinking.common.indexing.AliasLuceneIndex.java

License:Open Source License

public boolean loadIndex(String diskDir) {
    Directory dir = null;//w w  w . j  a va 2  s .c  o  m

    try {
        dir = new RAMDirectory(new MMapDirectory(new File(diskDir)));
        if (!IndexReader.indexExists(dir))
            return false;

        reader = IndexReader.open(dir);
        String[] keyArray = FieldCache.DEFAULT.getStrings(reader, "docID");
        //   int[] sizeArray= FieldCache.DEFAULT.getInts(reader, "size");
        searcher = new IndexSearcher(reader);

        for (int i = 0; i < keyArray.length; i++)
            docIDMap.put(keyArray[i], i);
    } catch (Exception e) {
        e.printStackTrace();
    }

    System.out.println("Loading index done22!!");
    return true;
}

From source file:ca.ualberta.entitylinking.common.indexing.WikipediaIndex.java

License:Open Source License

public void loadIndex(String diskDir) {
    Directory dir = null;/*from   ww w  .j  av a  2  s  .  c  o  m*/

    try {
        dir = new RAMDirectory(new MMapDirectory(new File(diskDir)));
        if (!IndexReader.indexExists(dir))
            return;

        reader = IndexReader.open(dir);
        searcher = new IndexSearcher(reader);
        System.out.println("Loading WikipediaIndex done!!!");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:cn.hbu.cs.esearch.index.DefaultDirectoryManager.java

License:Apache License

@Override
public Directory getDirectory(boolean create) throws IOException {
    if (!directory.exists() && create) {
        // create the parent directory
        directory.mkdirs();/*from  w  w  w  .j a  va 2  s  . com*/
    }

    if (create) {
        IndexSignature sig = null;
        if (directory.exists()) {
            sig = getCurrentIndexSignature();
        }

        if (sig == null) {
            File directoryFile = new File(directory, INDEX_DIRECTORY);
            sig = new IndexSignature(null);
            try {
                saveSignature(sig, directoryFile);
            } catch (IOException e) {
                throw e;
            }
        }
    }

    FSDirectory dir = null;
    switch (mode) {
    case SIMPLE:
        dir = new SimpleFSDirectory(directory);
        break;
    case NIO:
        dir = new NIOFSDirectory(directory);
        break;
    case MMAP:
        dir = new MMapDirectory(directory);
        break;
    }
    LOGGER.info("created Directory: " + dir);
    return dir;
}