当我使用StringField和StoredField时,Lucene Analyzer的用途是什么

时间:2015-01-21 10:45:20

标签: java lucene

如果我只使用StringField和StoredField进行索引和搜索,那么分析器的用途是什么?

由于StringFields没有标记化,我想知道这里分析仪的实际用途是什么?

我可以在没有分析仪的情况下编写lucene索引吗?

1 个答案:

答案 0 :(得分:0)

如果您使用StoredField,则根本不会发生索引。该文件只是存储。

如果您使用StringField,整个字段将被编入索引,并且使用分析器没有意义。我只是尝试运行以下代码:

Directory dir = new RAMDirectory();
Analyzer analyzer = null;
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_4_10_1, analyzer);
IndexWriter indexWriter = new IndexWriter(dir, iwc);

Document doc1 = new Document();
doc1.add(new StringField("title", "aa", Field.Store.YES));
indexWriter.addDocument(doc1);
indexWriter.commit();

IndexReader reader = IndexReader.open(dir);
IndexSearcher searcher = new IndexSearcher(reader);
// print results using MatchAllDocsQuery

它没有抛出异常而有效。