Search in sources :

Example 41 with RAMDirectory

use of org.apache.lucene.store.RAMDirectory in project querydsl by querydsl.

the class LuceneQueryTest method setUp.

@Before
public void setUp() throws Exception {
    final QDocument entityPath = new QDocument("doc");
    title = entityPath.title;
    year = entityPath.year;
    gross = entityPath.gross;
    idx = new RAMDirectory();
    writer = createWriter(idx);
    writer.addDocument(createDocument("Jurassic Park", "Michael Crichton", "It's a UNIX system! I know this!", 1990, 90.00));
    writer.addDocument(createDocument("Nummisuutarit", "Aleksis Kivi", "ESKO. Ja iloitset ja riemuitset?", 1864, 10.00));
    writer.addDocument(createDocument("The Lord of the Rings", "John R. R. Tolkien", "One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them", 1954, 89.00));
    writer.addDocument(createDocument("Introduction to Algorithms", "Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein", "Bubble sort", 1990, 30.50));
    writer.close();
    IndexReader reader = DirectoryReader.open(idx);
    searcher = new IndexSearcher(reader);
    query = new LuceneQuery(new LuceneSerializer(true, true), searcher);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) IndexReader(org.apache.lucene.index.IndexReader) RAMDirectory(org.apache.lucene.store.RAMDirectory) Before(org.junit.Before)

Example 42 with RAMDirectory

use of org.apache.lucene.store.RAMDirectory in project querydsl by querydsl.

the class LuceneQueryTest method empty_index_should_return_empty_list.

@Test
public void empty_index_should_return_empty_list() throws Exception {
    idx = new RAMDirectory();
    writer = createWriter(idx);
    writer.close();
    IndexReader reader = DirectoryReader.open(idx);
    searcher = new IndexSearcher(reader);
    query = new LuceneQuery(new LuceneSerializer(true, true), searcher);
    assertTrue(query.fetch().isEmpty());
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) IndexReader(org.apache.lucene.index.IndexReader) RAMDirectory(org.apache.lucene.store.RAMDirectory) Test(org.junit.Test)

Example 43 with RAMDirectory

use of org.apache.lucene.store.RAMDirectory in project jforum2 by rafaelsteil.

the class LuceneSettings method useRAMDirectory.

public void useRAMDirectory() throws Exception {
    this.directory = new RAMDirectory();
    IndexWriter writer = new IndexWriter(this.directory, this.analyzer, true);
    writer.close();
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) RAMDirectory(org.apache.lucene.store.RAMDirectory)

Example 44 with RAMDirectory

use of org.apache.lucene.store.RAMDirectory in project elasticsearch-suggest-plugin by spinscale.

the class ShardSuggestService method refresh.

public ShardSuggestRefreshResponse refresh(ShardSuggestRefreshRequest shardSuggestRefreshRequest) {
    String field = shardSuggestRefreshRequest.field();
    if (!Strings.hasLength(field)) {
        update();
    } else {
        resetIndexReader();
        HighFrequencyDictionary dict = dictCache.getIfPresent(field);
        if (dict != null)
            dictCache.refresh(field);
        RAMDirectory ramDirectory = ramDirectoryCache.getIfPresent(field);
        if (ramDirectory != null) {
            ramDirectory.close();
            ramDirectoryCache.invalidate(field);
        }
        SpellChecker spellChecker = spellCheckerCache.getIfPresent(field);
        if (spellChecker != null) {
            spellCheckerCache.refresh(field);
            try {
                spellChecker.close();
            } catch (IOException e) {
                logger.error("Could not close spellchecker in indexshard [{}] for field [{}]", e, indexShard, field);
            }
        }
        FSTCompletionLookup lookup = lookupCache.getIfPresent(field);
        if (lookup != null)
            lookupCache.refresh(field);
        for (FieldType fieldType : analyzingSuggesterCache.asMap().keySet()) {
            if (fieldType.field().equals(shardSuggestRefreshRequest.field())) {
                analyzingSuggesterCache.refresh(fieldType);
            }
        }
        for (FieldType fieldType : fuzzySuggesterCache.asMap().keySet()) {
            if (fieldType.field().equals(shardSuggestRefreshRequest.field())) {
                fuzzySuggesterCache.refresh(fieldType);
            }
        }
    }
    return new ShardSuggestRefreshResponse(shardId.index().name(), shardId.id());
}
Also used : ShardSuggestRefreshResponse(de.spinscale.elasticsearch.action.suggest.refresh.ShardSuggestRefreshResponse) HighFrequencyDictionary(org.apache.lucene.search.spell.HighFrequencyDictionary) SpellChecker(org.apache.lucene.search.spell.SpellChecker) FSTCompletionLookup(org.apache.lucene.search.suggest.fst.FSTCompletionLookup) IOException(java.io.IOException) RAMDirectory(org.apache.lucene.store.RAMDirectory)

Example 45 with RAMDirectory

use of org.apache.lucene.store.RAMDirectory in project camel by apache.

the class LuceneSuggestionStrategy method suggestEndpointOptions.

@Override
public String[] suggestEndpointOptions(Set<String> names, String unknownOption) {
    // each option must be on a separate line in a String
    StringBuilder sb = new StringBuilder();
    for (String name : names) {
        sb.append(name);
        sb.append("\n");
    }
    StringReader reader = new StringReader(sb.toString());
    try {
        PlainTextDictionary words = new PlainTextDictionary(reader);
        // use in-memory lucene spell checker to make the suggestions
        RAMDirectory dir = new RAMDirectory();
        SpellChecker checker = new SpellChecker(dir);
        checker.indexDictionary(words, new IndexWriterConfig(new KeywordAnalyzer()), false);
        return checker.suggestSimilar(unknownOption, maxSuggestions);
    } catch (Exception e) {
    // ignore
    }
    return null;
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) PlainTextDictionary(org.apache.lucene.search.spell.PlainTextDictionary) StringReader(java.io.StringReader) SpellChecker(org.apache.lucene.search.spell.SpellChecker) RAMDirectory(org.apache.lucene.store.RAMDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Aggregations

RAMDirectory (org.apache.lucene.store.RAMDirectory)183 Directory (org.apache.lucene.store.Directory)101 IndexWriter (org.apache.lucene.index.IndexWriter)82 Document (org.apache.lucene.document.Document)75 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)73 IndexSearcher (org.apache.lucene.search.IndexSearcher)43 IndexReader (org.apache.lucene.index.IndexReader)41 Test (org.junit.Test)35 TextField (org.apache.lucene.document.TextField)33 Field (org.apache.lucene.document.Field)29 Term (org.apache.lucene.index.Term)25 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)21 Before (org.junit.Before)21 IOException (java.io.IOException)19 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)19 Analyzer (org.apache.lucene.analysis.Analyzer)18 TopDocs (org.apache.lucene.search.TopDocs)16 DirectoryReader (org.apache.lucene.index.DirectoryReader)15 FilterDirectory (org.apache.lucene.store.FilterDirectory)15 FieldType (org.apache.lucene.document.FieldType)13