本文整理汇总了Java中org.apache.lucene.queries.TermsFilter类的典型用法代码示例。如果您正苦于以下问题:Java TermsFilter类的具体用法?Java TermsFilter怎么用?Java TermsFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TermsFilter类属于org.apache.lucene.queries包,在下文中一共展示了TermsFilter类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFilter
import org.apache.lucene.queries.TermsFilter; //导入依赖的package包/类
@Override
public Filter getFilter(Element e) throws ParserException {
List<BytesRef> terms = new ArrayList<>();
String text = DOMUtils.getNonBlankTextOrFail(e);
String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
TokenStream ts = null;
try {
ts = analyzer.tokenStream(fieldName, text);
TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class);
BytesRef bytes = termAtt.getBytesRef();
ts.reset();
while (ts.incrementToken()) {
termAtt.fillBytesRef();
terms.add(BytesRef.deepCopyOf(bytes));
}
ts.end();
}
catch (IOException ioe) {
throw new RuntimeException("Error constructing terms from index:" + ioe);
} finally {
IOUtils.closeWhileHandlingException(ts);
}
return new TermsFilter(fieldName, terms);
}
示例2: terms
import org.apache.lucene.queries.TermsFilter; //导入依赖的package包/类
/**
* Returns a filter that forces a given field to be one of the given values
*/
public static Filter terms(final String field, final Collection<?> values) {
if (CollectionUtils.isEmpty(values)) {
return null;
}
final TermsFilter filter = new TermsFilter();
int count = 0;
for (final Object object : values) {
final String term = object == null ? null : StringUtils.trimToNull("" + object);
if (term != null) {
/* todo addterm*/
//filter.addTerm(new Term(field, term));
count++;
}
}
return count == 0 ? null : filter;
}
示例3: addTerms
import org.apache.lucene.queries.TermsFilter; //导入依赖的package包/类
/**
* Returns a filter that forces a given field to be one of the given values
*/
public void addTerms(final String field, final Collection<?> values) {
if (CollectionUtils.isEmpty(values)) {
return;
}
boolean used = false;
final TermsFilter filter = new TermsFilter();
for (final Object object : values) {
final String term = CoercionHelper.coerce(String.class, object);
if (StringUtils.isNotEmpty(term)) {
/* todo addterm */
//filter.addTerm(new Term(field, term));
used = true;
}
}
if (used) {
add(filter);
}
}
示例4: makeFilter
import org.apache.lucene.queries.TermsFilter; //导入依赖的package包/类
@Override
public Filter makeFilter(SpatialArgs args) {
final SpatialOperation op = args.getOperation();
if (op != SpatialOperation.Intersects)
throw new UnsupportedSpatialOperation(op);
Shape shape = args.getShape();
int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct));
List<Cell> cells = grid.getCells(shape, detailLevel,
false,//no parents
true);//simplify
BytesRef[] terms = new BytesRef[cells.size()];
int i = 0;
for (Cell cell : cells) {
terms[i++] = new BytesRef(cell.getTokenString());//TODO use cell.getTokenBytes()
}
return new TermsFilter(getFieldName(), terms);
}
示例5: makeFilter
import org.apache.lucene.queries.TermsFilter; //导入依赖的package包/类
@Override
public Filter makeFilter(SpatialArgs args) {
final SpatialOperation op = args.getOperation();
if (op != SpatialOperation.Intersects)
throw new UnsupportedSpatialOperation(op);
Shape shape = args.getShape();
int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct));
List<Node> cells = grid.getNodes(shape, detailLevel,
false,//no parents
true);//simplify
BytesRef[] terms = new BytesRef[cells.size()];
int i = 0;
for (Node cell : cells) {
terms[i++] = new BytesRef(cell.getTokenString());
}
return new TermsFilter(getFieldName(), terms);
}
示例6: getFilter
import org.apache.lucene.queries.TermsFilter; //导入依赖的package包/类
@Override
public Filter getFilter(Element e) throws ParserException {
List<BytesRef> terms = new ArrayList<BytesRef>();
String text = DOMUtils.getNonBlankTextOrFail(e);
String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
try {
TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(text));
TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class);
Term term = null;
BytesRef bytes = termAtt.getBytesRef();
ts.reset();
while (ts.incrementToken()) {
termAtt.fillBytesRef();
terms.add(BytesRef.deepCopyOf(bytes));
}
ts.end();
ts.close();
}
catch (IOException ioe) {
throw new RuntimeException("Error constructing terms from index:" + ioe);
}
return new TermsFilter(fieldName, terms);
}
示例7: makeFilter
import org.apache.lucene.queries.TermsFilter; //导入依赖的package包/类
@Override
public Filter makeFilter(SpatialArgs args) {
final SpatialOperation op = args.getOperation();
if (op != SpatialOperation.Intersects)
throw new UnsupportedSpatialOperation(op);
Shape shape = args.getShape();
int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct));
List<Cell> cells = grid.getCells(shape, detailLevel, false,// no parents
true);// simplify
BytesRef[] terms = new BytesRef[cells.size()];
int i = 0;
for (Cell cell : cells) {
terms[i++] = new BytesRef(cell.getTokenString());
}
return new TermsFilter(getFieldName(), terms);
}
示例8: makeFilter
import org.apache.lucene.queries.TermsFilter; //导入依赖的package包/类
@Override
public Filter makeFilter(SpatialArgs args) {
final SpatialOperation op = args.getOperation();
if (op != SpatialOperation.Intersects)
throw new UnsupportedSpatialOperation(op);
Shape shape = args.getShape();
int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct));
List<Cell> cells = grid.getCells(shape, detailLevel,
false,//no parents
true);//simplify
BytesRef[] terms = new BytesRef[cells.size()];
int i = 0;
for (Cell cell : cells) {
terms[i++] = new BytesRef(cell.getTokenString());
}
return new TermsFilter(getFieldName(), terms);
}
示例9: getFilter
import org.apache.lucene.queries.TermsFilter; //导入依赖的package包/类
@Override
public Filter getFilter(Element e) throws ParserException {
List<BytesRef> terms = new ArrayList<BytesRef>();
String text = DOMUtils.getNonBlankTextOrFail(e);
String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
TokenStream ts = null;
try {
ts = analyzer.tokenStream(fieldName, text);
TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class);
BytesRef bytes = termAtt.getBytesRef();
ts.reset();
while (ts.incrementToken()) {
termAtt.fillBytesRef();
terms.add(BytesRef.deepCopyOf(bytes));
}
ts.end();
}
catch (IOException ioe) {
throw new RuntimeException("Error constructing terms from index:" + ioe);
} finally {
IOUtils.closeWhileHandlingException(ts);
}
return new TermsFilter(fieldName, terms);
}
示例10: toFilter
import org.apache.lucene.queries.TermsFilter; //导入依赖的package包/类
public Filter toFilter () {
// Regular expression
if (this.regex)
return new QueryWrapperFilter(
new RegexpQuery(new org.apache.lucene.index.Term(
this.field, this.term)));
// Simple term
return new TermsFilter(
new org.apache.lucene.index.Term(this.field, this.term));
}
示例11: makeFilter
import org.apache.lucene.queries.TermsFilter; //导入依赖的package包/类
@Override
Filter makeFilter(String fname, BytesRef[] bytesRefs) {
return new TermsFilter(fname, bytesRefs);
}
示例12: makeFilter
import org.apache.lucene.queries.TermsFilter; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
Filter makeFilter(String fname, Iterator<BytesRef> it) {
return new TermsFilter(fname, IteratorUtils.toList(it));
}