本文整理汇总了Java中org.apache.lucene.analysis.CannedBinaryTokenStream类的典型用法代码示例。如果您正苦于以下问题:Java CannedBinaryTokenStream类的具体用法?Java CannedBinaryTokenStream怎么用?Java CannedBinaryTokenStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CannedBinaryTokenStream类属于org.apache.lucene.analysis包,在下文中一共展示了CannedBinaryTokenStream类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTermMinMaxRandom
import org.apache.lucene.analysis.CannedBinaryTokenStream; //导入依赖的package包/类
public void testTermMinMaxRandom() throws Exception {
// NOTE: don't use @SuppressCodecs("Lucene3x") on the entire test
// class, so that we still run the other test methods
// with Lucene3x. This is important, to have some
// testing of Terms.getMin/Max on older indices.
assumeFalse("test writes binary terms", Codec.getDefault() instanceof Lucene3xCodec);
Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), dir);
int numDocs = atLeast(100);
BytesRef minTerm = null;
BytesRef maxTerm = null;
for(int i=0;i<numDocs;i++ ){
Document doc = new Document();
Field field = new TextField("field", "", Field.Store.NO);
doc.add(field);
//System.out.println(" doc " + i);
CannedBinaryTokenStream.BinaryToken[] tokens = new CannedBinaryTokenStream.BinaryToken[atLeast(10)];
for(int j=0;j<tokens.length;j++) {
byte[] bytes = new byte[TestUtil.nextInt(random(), 1, 20)];
random().nextBytes(bytes);
BytesRef tokenBytes = new BytesRef(bytes);
//System.out.println(" token " + tokenBytes);
if (minTerm == null || tokenBytes.compareTo(minTerm) < 0) {
//System.out.println(" ** new min");
minTerm = tokenBytes;
}
if (maxTerm == null || tokenBytes.compareTo(maxTerm) > 0) {
//System.out.println(" ** new max");
maxTerm = tokenBytes;
}
tokens[j] = new CannedBinaryTokenStream.BinaryToken(tokenBytes);
}
field.setTokenStream(new CannedBinaryTokenStream(tokens));
w.addDocument(doc);
}
IndexReader r = w.getReader();
Terms terms = MultiFields.getTerms(r, "field");
assertEquals(minTerm, terms.getMin());
assertEquals(maxTerm, terms.getMax());
r.close();
w.close();
dir.close();
}