Lucene 4.2.1 没有 StandardAnalyzer,我不确定如何实现一个不会改变源文本的基本分析器。任何指针?
final SimpleFSDirectory DIRECTORY = new SimpleFSDirectory(new File(ELEMENTS_INDEX_DIR));
IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_42, new Analyzer() {
@Override
protected TokenStreamComponents createComponents(String s, Reader reader) {
return null;
}
});
IndexWriter indexWriter = new IndexWriter(DIRECTORY, indexWriterConfig);
List<ModelObject> elements = dao.getAll();
for (ModelObject element : elements) {
Document document = new Document();
document.add(new StringField("id", String.valueOf(element.getId()), Field.Store.YES));
document.add(new TextField("name", element.getName(), Field.Store.YES));
indexWriter.addDocument(document);
}
indexWriter.close();