开发者

Indexing lucene document with different analysers

Is it okay to index the lucene documents with two different analysers? Like i need to support both case-sensitive and case-insensitive search. So wondering if I ca开发者_如何学JAVAn use two analysers for same document.

writer.addDocument(doc,new StandardAnalyzer(Version.LUCENE_30)); writer.addDocument(doc,new custom_analyser);

I am planning to have a custom analyser that supports all filter the standard analyser does except for lowercase filter. While I try to search results from indices, I think we might end up getting duplicates..

Any comment/ideas?

EDIT: @Simon

Analyzer defaultAnalyzer = new StandardAnalyzer(Version.LUCENE_30);
PerFieldAnalyzerWrapper wrapper = new PerFieldAnalyzerWrapper(defaultAnalyzer);
wrapper.addAnalyzer("CaseSensitiveContents", new WhitespaceAnalyzer());

writer = new IndexWriter(FSDirectory.open(index), wrapper, true, 
                         new IndexWriter.MaxFieldLength(100))

doc.add(new Field("contents", parser.getReader(), TermVector.YES));
doc.add(new Field("CaseSensitiveContents", parser.getReader(), TermVector.YES));
writer.add(doc)


Your example code would add two almost identical documents (except their casing) to your index.

How about adding two fields to one document, one being case sensitive, one not? You can use the PerFieldAnalyzer for this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜