本文整理汇总了Java中org.apache.lucene.search.TermRangeQuery.newStringRange方法的典型用法代码示例。如果您正苦于以下问题:Java TermRangeQuery.newStringRange方法的具体用法?Java TermRangeQuery.newStringRange怎么用?Java TermRangeQuery.newStringRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.TermRangeQuery
的用法示例。
在下文中一共展示了TermRangeQuery.newStringRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReaderChaining
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
public void testReaderChaining() throws Exception {
assertTrue(reader.getRefCount() > 0);
IndexReader wrappedReader = SlowCompositeReaderWrapper.wrap(reader);
wrappedReader = new ParallelAtomicReader((AtomicReader) wrappedReader);
IndexSearcher searcher = newSearcher(wrappedReader);
TermRangeQuery query = TermRangeQuery.newStringRange("field", "a", "z", true, true);
searcher.search(query, 5);
reader.close(); // close original child reader
try {
searcher.search(query, 5);
} catch (AlreadyClosedException ace) {
assertEquals(
"this IndexReader cannot be used anymore as one of its child readers was closed",
ace.getMessage()
);
} finally {
// shutdown executor: in case of wrap-wrap-wrapping
searcher.getIndexReader().close();
}
}
示例2: testTermRangeQueryBigger
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
@Test
public void testTermRangeQueryBigger() {
JsonObject json = Json.createObjectBuilder()
.add("query", Json.createObjectBuilder()
.add("type", "RangeQuery")
.add("rangeType", "String")
.add("field", "field")
.add("lowerTerm", "value")
.add("upperTerm", JsonValue.NULL)
.add("includeLower", JsonValue.FALSE)
.add("includeUpper", JsonValue.FALSE))
.build();
QueryData q = new QueryData(new StringReader(json.toString()), queryConverter);
TermRangeQuery query = TermRangeQuery.newStringRange("field", "value", null, false, false);
assertEquals(query, q.query);
}
示例3: testTermRangeQueryLower
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
@Test
public void testTermRangeQueryLower() {
JsonObject json = Json.createObjectBuilder()
.add("query", Json.createObjectBuilder()
.add("type", "RangeQuery")
.add("rangeType", "String")
.add("field", "field")
.add("lowerTerm", JsonValue.NULL)
.add("upperTerm", "value")
.add("includeLower", JsonValue.TRUE)
.add("includeUpper", JsonValue.TRUE))
.build();
QueryData q = new QueryData(new StringReader(json.toString()), queryConverter);
TermRangeQuery query = TermRangeQuery.newStringRange("field", null, "value", true, true);
assertEquals(query, q.query);
}
示例4: build
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
@Override
public TermRangeQuery build(QueryNode queryNode) throws QueryNodeException {
TermRangeQueryNode rangeNode = (TermRangeQueryNode) queryNode;
FieldQueryNode upper = rangeNode.getUpperBound();
FieldQueryNode lower = rangeNode.getLowerBound();
String field = StringUtils.toString(rangeNode.getField());
String lowerText = lower.getTextAsString();
String upperText = upper.getTextAsString();
if (lowerText.length() == 0) {
lowerText = null;
}
if (upperText.length() == 0) {
upperText = null;
}
TermRangeQuery rangeQuery = TermRangeQuery.newStringRange(field, lowerText, upperText, rangeNode
.isLowerInclusive(), rangeNode.isUpperInclusive());
MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod) queryNode
.getTag(MultiTermRewriteMethodProcessor.TAG_ID);
if (method != null) {
rangeQuery.setRewriteMethod(method);
}
return rangeQuery;
}
示例5: newRangeQuery
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
@Override
protected Query newRangeQuery(String field, String part1, String part2,
boolean startInclusive, boolean endInclusive) {
if (isPass2ResolvingPhrases) {
// Must use old-style RangeQuery in order to produce a BooleanQuery
// that can be turned into SpanOr clause
TermRangeQuery rangeQuery = TermRangeQuery.newStringRange(field, part1, part2, startInclusive, endInclusive);
rangeQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
return rangeQuery;
}
return super.newRangeQuery(field, part1, part2, startInclusive, endInclusive);
}
示例6: toRangeQuery
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
private Query toRangeQuery(RangeTerm range) {
return TermRangeQuery.newStringRange(
range.getField(),
range.hasMin() ? range.getMin() : null,
range.hasMax() ? range.getMax() : null,
range.getMinInclusive(),
range.getMaxInclusive());
}
示例7: test
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
public void test() throws Exception {
assertTrue(reader.getRefCount() > 0);
IndexSearcher searcher = newSearcher(reader);
TermRangeQuery query = TermRangeQuery.newStringRange("field", "a", "z", true, true);
searcher.search(query, 5);
reader.close();
try {
searcher.search(query, 5);
} catch (AlreadyClosedException ace) {
// expected
}
}
示例8: getRangeQuery
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
/** DateField specific range query */
public Query getRangeQuery(QParser parser, SchemaField sf, Date part1, Date part2, boolean minInclusive, boolean maxInclusive) {
return TermRangeQuery.newStringRange(
sf.getName(),
part1 == null ? null : toInternal(part1),
part2 == null ? null : toInternal(part2),
minInclusive, maxInclusive);
}
示例9: getRangeQuery
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
/**
* Returns a Query instance for doing range searches on this field type. {@link org.apache.solr.search.SolrQueryParser}
* currently passes part1 and part2 as null if they are '*' respectively. minInclusive and maxInclusive are both true
* currently by SolrQueryParser but that may change in the future. Also, other QueryParser implementations may have
* different semantics.
* <p/>
* Sub-classes should override this method to provide their own range query implementation. They should strive to
* handle nulls in part1 and/or part2 as well as unequal minInclusive and maxInclusive parameters gracefully.
*
* @param parser the {@link org.apache.solr.search.QParser} calling the method
* @param field the schema field
* @param part1 the lower boundary of the range, nulls are allowed.
* @param part2 the upper boundary of the range, nulls are allowed
* @param minInclusive whether the minimum of the range is inclusive or not
* @param maxInclusive whether the maximum of the range is inclusive or not
* @return a Query instance to perform range search according to given parameters
*
*/
public Query getRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
// TODO: change these all to use readableToIndexed/bytes instead (e.g. for unicode collation)
if (field.hasDocValues() && !field.indexed()) {
if (field.multiValued()) {
return new ConstantScoreQuery(DocTermOrdsRangeFilter.newBytesRefRange(
field.getName(),
part1 == null ? null : new BytesRef(toInternal(part1)),
part2 == null ? null : new BytesRef(toInternal(part2)),
minInclusive, maxInclusive));
} else {
return new ConstantScoreQuery(FieldCacheRangeFilter.newStringRange(
field.getName(),
part1 == null ? null : toInternal(part1),
part2 == null ? null : toInternal(part2),
minInclusive, maxInclusive));
}
} else {
MultiTermQuery rangeQuery = TermRangeQuery.newStringRange(
field.getName(),
part1 == null ? null : toInternal(part1),
part2 == null ? null : toInternal(part2),
minInclusive, maxInclusive);
rangeQuery.setRewriteMethod(getRewriteMethod(parser, field));
return rangeQuery;
}
}
示例10: testCollatedRange
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
@Test
public void testCollatedRange() throws Exception {
QueryParser qp = getParserConfig(new MockCollationAnalyzer());
setAnalyzeRangeTerms(qp, true);
Query expected = TermRangeQuery.newStringRange(getDefaultField(), "collatedabc", "collateddef", true, true);
Query actual = getQuery("[abc TO def]", qp);
Assert.assertEquals(expected, actual);
}
示例11: getRangeQuery
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
/**
* Returns a Query instance for doing range searches on this field type. {@link org.apache.solr.search.SolrQueryParser}
* currently passes part1 and part2 as null if they are '*' respectively. minInclusive and maxInclusive are both true
* currently by SolrQueryParser but that may change in the future. Also, other QueryParser implementations may have
* different semantics.
* <p/>
* Sub-classes should override this method to provide their own range query implementation. They should strive to
* handle nulls in part1 and/or part2 as well as unequal minInclusive and maxInclusive parameters gracefully.
*
* @param field the schema field
* @param part1 the lower boundary of the range, nulls are allowed.
* @param part2 the upper boundary of the range, nulls are allowed
* @param minInclusive whether the minimum of the range is inclusive or not
* @param maxInclusive whether the maximum of the range is inclusive or not
* @return a Query instance to perform range search according to given parameters
*
*/
public Query getRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
// TODO: change these all to use readableToIndexed/bytes instead (e.g. for unicode collation)
if (field.hasDocValues() && !field.indexed()) {
if (field.multiValued()) {
return new ConstantScoreQuery(DocTermOrdsRangeFilter.newBytesRefRange(
field.getName(),
part1 == null ? null : new BytesRef(toInternal(part1)),
part2 == null ? null : new BytesRef(toInternal(part2)),
minInclusive, maxInclusive));
} else {
return new ConstantScoreQuery(FieldCacheRangeFilter.newStringRange(
field.getName(),
part1 == null ? null : toInternal(part1),
part2 == null ? null : toInternal(part2),
minInclusive, maxInclusive));
}
} else {
MultiTermQuery rangeQuery = TermRangeQuery.newStringRange(
field.getName(),
part1 == null ? null : toInternal(part1),
part2 == null ? null : toInternal(part2),
minInclusive, maxInclusive);
rangeQuery.setRewriteMethod(getRewriteMethod(parser, field));
return rangeQuery;
}
}
示例12: getTermsQuery
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
/**
* Creates a term filter for a set of terms.
* @param terms some terms
* @param mustMatchAll if true all terms must match ('AND' operation)
* @return the filter
*/
static Query getTermsQuery(Map<String, ?> terms, boolean mustMatchAll) {
BooleanQuery.Builder fb = new BooleanQuery.Builder();
int addedTerms = 0;
boolean noop = true;
Query bfb = null;
for (Map.Entry<String, ?> term : terms.entrySet()) {
Object val = term.getValue();
if (!StringUtils.isBlank(term.getKey()) && val != null) {
Matcher matcher = Pattern.compile(".*(<|>|<=|>=)$").matcher(term.getKey().trim());
bfb = new TermQuery(new Term(term.getKey(), val.toString()));
if (matcher.matches() && val instanceof Number) {
String key = term.getKey().replaceAll("[<>=\\s]+$", "");
if (">".equals(matcher.group(1))) {
bfb = TermRangeQuery.newStringRange(key, val.toString(), null, false, false);
} else if ("<".equals(matcher.group(1))) {
bfb = TermRangeQuery.newStringRange(key, null, val.toString(), false, false);
} else if (">=".equals(matcher.group(1))) {
bfb = TermRangeQuery.newStringRange(key, val.toString(), null, true, false);
} else if ("<=".equals(matcher.group(1))) {
bfb = TermRangeQuery.newStringRange(key, null, val.toString(), false, true);
}
}
if (mustMatchAll) {
fb.add(bfb, BooleanClause.Occur.MUST);
} else {
fb.add(bfb, BooleanClause.Occur.SHOULD);
}
addedTerms++;
noop = false;
}
}
if (addedTerms == 1 && bfb != null) {
return bfb;
}
return noop ? null : fb.build();
}
示例13: createRangeQuery
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
private Query createRangeQuery(JsonObject query) {
String field = query.getString("field");
boolean includeLower = query.getBoolean("includeLower");
boolean includeUpper = query.getBoolean("includeUpper");
boolean lower = query.get("lowerTerm") != JsonValue.NULL;
boolean upper = query.get("upperTerm") != JsonValue.NULL;
switch (query.getString("rangeType")) {
case "String":
return TermRangeQuery.newStringRange(field, lower ? query.getString("lowerTerm") : null, upper ? query.getString("upperTerm") : null, includeLower, includeUpper);
case "Int":
Integer iLowerValue = lower ? query.getInt("lowerTerm") : Integer.MIN_VALUE;
Integer iUpperValue = upper ? query.getInt("upperTerm") : Integer.MAX_VALUE;
if (!includeLower && iLowerValue != null)
iLowerValue += 1;
if (!includeUpper && iUpperValue != null)
iUpperValue -= 1;
return IntPoint.newRangeQuery(field, iLowerValue, iUpperValue);
case "Long":
Long lLowerValue = lower ? query.getJsonNumber("lowerTerm").longValue() : Long.MIN_VALUE;
Long lUpperValue = upper ? query.getJsonNumber("upperTerm").longValue() : Long.MAX_VALUE;
if (!includeLower && lLowerValue != null)
lLowerValue += 1;
if (!includeUpper && lUpperValue != null)
lUpperValue -= 1;
return LongPoint.newRangeQuery(field, lLowerValue, lUpperValue);
case "Double":
Double dLowerValue = lower ? query.getJsonNumber("lowerTerm").doubleValue() : Double.NEGATIVE_INFINITY;
Double dUpperValue = upper ? query.getJsonNumber("upperTerm").doubleValue() : Double.POSITIVE_INFINITY;
if (!includeLower && dLowerValue != null)
dLowerValue = Math.nextUp(dLowerValue);
if (!includeUpper && dUpperValue != null)
dUpperValue = Math.nextDown(dUpperValue);
return DoublePoint.newRangeQuery(field, dLowerValue, dUpperValue);
}
return null;
}
示例14: rq_ie
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
private Query rq_ie(String field, String part1, String part2) {
return TermRangeQuery.newStringRange(field, part1, part2, true, false);
}
示例15: testCollatedRange
import org.apache.lucene.search.TermRangeQuery; //导入方法依赖的package包/类
public void testCollatedRange() throws Exception {
CommonQueryParserConfiguration qp = getParserConfig(new MockCollationAnalyzer());
Query expected = TermRangeQuery.newStringRange(getDefaultField(), "collatedabc", "collateddef", true, true);
Query actual = getQuery("[abc TO def]", qp);
assertEquals(expected, actual);
}