Search in sources :

Example 6 with Similarity

use of org.apache.lucene.search.Similarity in project neo4j-mobile-android by neo4j-contrib.

the class LuceneDataSource method getIndexWriter.

synchronized IndexWriter getIndexWriter(IndexIdentifier identifier) {
    if (closed)
        throw new IllegalStateException("Index has been shut down");
    Pair<IndexWriter, AtomicBoolean> writer = indexWriters.get(identifier);
    if (writer != null) {
        return writer.first();
    }
    try {
        Directory dir = getDirectory(baseStorePath, identifier);
        directoryExists(dir);
        IndexType type = getType(identifier);
        IndexWriterConfig writerConfig = new IndexWriterConfig(LUCENE_VERSION, type.analyzer);
        writerConfig.setIndexDeletionPolicy(new MultipleBackupDeletionPolicy());
        Similarity similarity = type.getSimilarity();
        if (similarity != null) {
            writerConfig.setSimilarity(similarity);
        }
        IndexWriter indexWriter = new IndexWriter(dir, writerConfig);
        writer = Pair.of(indexWriter, new AtomicBoolean());
        // TODO We should tamper with this value and see how it affects the
        // general performance. Lucene docs says rather <10 for mixed
        // reads/writes
        // writer.setMergeFactor( 8 );
        indexWriters.put(identifier, writer);
        return writer.first();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Similarity(org.apache.lucene.search.Similarity) IndexWriter(org.apache.lucene.index.IndexWriter) IOException(java.io.IOException) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Aggregations

Similarity (org.apache.lucene.search.Similarity)6 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 IndexWriter (org.apache.lucene.index.IndexWriter)2 Directory (org.apache.lucene.store.Directory)2 FSDirectory (org.apache.lucene.store.FSDirectory)2 IndexReader (org.apache.lucene.index.IndexReader)1 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)1 SnapshotDeletionPolicy (org.apache.lucene.index.SnapshotDeletionPolicy)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 DefaultSimilarity (org.apache.lucene.search.DefaultSimilarity)1 Explanation (org.apache.lucene.search.Explanation)1 Searcher (org.apache.lucene.search.Searcher)1 Weight (org.apache.lucene.search.Weight)1 Bits (org.apache.lucene.util.Bits)1