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);
}
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());
}
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();
}
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());
}
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;
}
Aggregations