Memory 内存索引和lucene文件索引之间有什么区别?
我不熟悉内存索引的概念。我们目前正在使用lucene文件索引技术对记录进行索引和搜索。Memory 内存索引和lucene文件索引之间有什么区别?,memory,indexing,lucene,Memory,Indexing,Lucene,我不熟悉内存索引的概念。我们目前正在使用lucene文件索引技术对记录进行索引和搜索。 您能告诉我如何实现内存内索引,以及这种类型的索引与lucene文件索引相比有什么优势吗?检查这个答案,以比较FSDirectory和内存内RAMDIrectory 如何使用RAMDirectory: RAMDirectory idx = new RAMDirectory(); IndexWriterConfig iwc = new IndexWriterConfig(analyzer); iwc.setO
您能告诉我如何实现内存内索引,以及这种类型的索引与lucene文件索引相比有什么优势吗?检查这个答案,以比较FSDirectory和内存内RAMDIrectory 如何使用RAMDirectory:
RAMDirectory idx = new RAMDirectory();
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
IndexWriter writer = new IndexWriter(idx, iwc);
Iterator<Map.Entry<String, String>> it = inputCategoryMap.entrySet().iterator();
while (it.hasNext()) {
Document doc = new Document();
Map.Entry<String, String> pair = it.next();
FieldType contentType = new FieldType();
contentType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
contentType.setStored(true);
contentType.setTokenized(true);
contentType.setStoreTermVectors(true);
doc.add(new Field(TITLE, pair.getKey(), TextField.TYPE_STORED));
doc.add(new Field(CONTENT, pair.getValue(),contentType ));
dcmnts.add(doc);
}
writer.addDocuments(dcmnts);
writer.commit();
System.out.println("No of documents added in the index "+writer.maxDoc());
writer.close();
System.out.println("Size consumed by Ram "+idx.ramBytesUsed()+"\nTime Consumed By Lucene "+stopwatch.getTime(TimeUnit.SECONDS));
检查此答案以比较FSDirectory和内存中的RAMDIrectory 如何使用RAMDirectory:
RAMDirectory idx = new RAMDirectory();
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
IndexWriter writer = new IndexWriter(idx, iwc);
Iterator<Map.Entry<String, String>> it = inputCategoryMap.entrySet().iterator();
while (it.hasNext()) {
Document doc = new Document();
Map.Entry<String, String> pair = it.next();
FieldType contentType = new FieldType();
contentType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
contentType.setStored(true);
contentType.setTokenized(true);
contentType.setStoreTermVectors(true);
doc.add(new Field(TITLE, pair.getKey(), TextField.TYPE_STORED));
doc.add(new Field(CONTENT, pair.getValue(),contentType ));
dcmnts.add(doc);
}
writer.addDocuments(dcmnts);
writer.commit();
System.out.println("No of documents added in the index "+writer.maxDoc());
writer.close();
System.out.println("Size consumed by Ram "+idx.ramBytesUsed()+"\nTime Consumed By Lucene "+stopwatch.getTime(TimeUnit.SECONDS));