2010-05-23 167 views

回答

6

Got it! FilteredTermEnum子類(FuzzyTermEnum,RegexTermEnum,WildcardTermEnum)正是我所需要的。

這裏有一個簡單的例子:

FSDirectory dir = FSDirectory.open(new File("index")); 
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), 
    true, new IndexWriter.MaxFieldLength(20)); 
IndexReader reader = IndexReader.open(dir); 

Document doc = new Document(); 
doc.add(new Field(
    "text", 
    "Life #consists not in #holding good cards, but in playing those you hold well.", 
    Field.Store.NO, Field.Index.ANALYZED)); 
writer.addDocument(doc); 
writer.close(); 

WildcardTermEnum tagsEnum = new WildcardTermEnum(reader, new Term("text", "#*")); 
do { 
    System.out.println(tagsEnum.term()); 
} while (tagsEnum.next()); 
相關問題