本文整理汇总了Java中org.apache.lucene.analysis.miscellaneous.LimitTokenCountAnalyzer类的典型用法代码示例。如果您正苦于以下问题:Java LimitTokenCountAnalyzer类的具体用法?Java LimitTokenCountAnalyzer怎么用?Java LimitTokenCountAnalyzer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LimitTokenCountAnalyzer类属于org.apache.lucene.analysis.miscellaneous包,在下文中一共展示了LimitTokenCountAnalyzer类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.apache.lucene.analysis.miscellaneous.LimitTokenCountAnalyzer; //导入依赖的package包/类
protected void init(boolean write) throws IOException {
// configure/initialize lucene
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_44);
IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_44,
new LimitTokenCountAnalyzer(analyzer, Integer.MAX_VALUE));
// if index doesn't exist, create it (otherwise you get an error trying to open the reader)
if (write || !DirectoryReader.indexExists(directory)) {
this.writer = new IndexWriter(directory, conf);
this.writer.commit(); // for ensuring the index exists the first time
}
this.reader = DirectoryReader.open(directory);
this.searcher = new IndexSearcher(this.reader);
this.parser = new QueryParser(Version.LUCENE_44, "description", analyzer);
this.parser.setDefaultOperator(Operator.AND);
// get the unique SAB's
Set<String> sabs = new HashSet<>();
Fields fields = MultiFields.getFields(this.reader);
if (fields != null) {
Terms terms = fields.terms("sab");
TermsEnum itr = terms.iterator(null);
BytesRef bytes = null;
while((bytes = itr.next()) != null) {
String term = new String(bytes.bytes, bytes.offset, bytes.length);
sabs.add(term);
}
}
this.systems = Collections.unmodifiableSet(sabs);
}