Понял! 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());