本文整理汇总了Java中org.apache.lucene.document.IntPoint.newRangeQuery方法的典型用法代码示例。如果您正苦于以下问题:Java IntPoint.newRangeQuery方法的具体用法?Java IntPoint.newRangeQuery怎么用?Java IntPoint.newRangeQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.document.IntPoint
的用法示例。
在下文中一共展示了IntPoint.newRangeQuery方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIntRangeQueryWithNoBounds
import org.apache.lucene.document.IntPoint; //导入方法依赖的package包/类
@Test
public void testIntRangeQueryWithNoBounds() {
JsonObject json = Json.createObjectBuilder()
.add("query", Json.createObjectBuilder()
.add("type", "RangeQuery")
.add("rangeType", "Int")
.add("field", "field")
.add("lowerTerm", JsonValue.NULL)
.add("upperTerm", JsonValue.NULL)
.add("includeLower", JsonValue.FALSE)
.add("includeUpper", JsonValue.TRUE))
.build();
QueryData q = new QueryData(new StringReader(json.toString()), queryConverter);
Query query = IntPoint.newRangeQuery("field", Integer.MIN_VALUE + 1, Integer.MAX_VALUE);
assertEquals(query, q.query);
}
示例2: testIntRangeQuery
import org.apache.lucene.document.IntPoint; //导入方法依赖的package包/类
@Test
public void testIntRangeQuery() {
JsonObject json = Json.createObjectBuilder()
.add("query", Json.createObjectBuilder()
.add("type", "RangeQuery")
.add("rangeType", "Int")
.add("field", "field")
.add("lowerTerm", 1)
.add("upperTerm", 5)
.add("includeLower", JsonValue.FALSE)
.add("includeUpper", JsonValue.TRUE))
.build();
QueryData q = new QueryData(new StringReader(json.toString()), queryConverter);
Query query = IntPoint.newRangeQuery("field", 2, 5);
assertEquals(query, q.query);
}
示例3: rangeQuery
import org.apache.lucene.document.IntPoint; //导入方法依赖的package包/类
@Override
Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
boolean includeLower, boolean includeUpper,
boolean hasDocValues) {
int l = Integer.MIN_VALUE;
int u = Integer.MAX_VALUE;
if (lowerTerm != null) {
l = parse(lowerTerm, true);
// if the lower bound is decimal:
// - if the bound is positive then we increment it:
// if lowerTerm=1.5 then the (inclusive) bound becomes 2
// - if the bound is negative then we leave it as is:
// if lowerTerm=-1.5 then the (inclusive) bound becomes -1 due to the call to longValue
boolean lowerTermHasDecimalPart = hasDecimalPart(lowerTerm);
if ((lowerTermHasDecimalPart == false && includeLower == false) ||
(lowerTermHasDecimalPart && signum(lowerTerm) > 0)) {
if (l == Integer.MAX_VALUE) {
return new MatchNoDocsQuery();
}
++l;
}
}
if (upperTerm != null) {
u = parse(upperTerm, true);
boolean upperTermHasDecimalPart = hasDecimalPart(upperTerm);
if ((upperTermHasDecimalPart == false && includeUpper == false) ||
(upperTermHasDecimalPart && signum(upperTerm) < 0)) {
if (u == Integer.MIN_VALUE) {
return new MatchNoDocsQuery();
}
--u;
}
}
Query query = IntPoint.newRangeQuery(field, l, u);
if (hasDocValues) {
Query dvQuery = SortedNumericDocValuesField.newRangeQuery(field, l, u);
query = new IndexOrDocValuesQuery(query, dvQuery);
}
return query;
}
示例4: createRangeQuery
import org.apache.lucene.document.IntPoint; //导入方法依赖的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;
}
示例5: searchFeaturesInInterval
import org.apache.lucene.document.IntPoint; //导入方法依赖的package包/类
public IndexSearchResult<FeatureIndexEntry> searchFeaturesInInterval(List<? extends FeatureFile> files, int start,
int end, Chromosome chromosome)
throws IOException {
List<? extends FeatureFile> indexedFiles =
files.stream().filter(f -> fileManager.indexForFeatureFileExists(f))
.collect(Collectors.toList());
if (indexedFiles.isEmpty()) {
return new IndexSearchResult<>(Collections.emptyList(), false, 0);
}
SimpleFSDirectory[] indexes = fileManager.getIndexesForFiles(files);
try (MultiReader reader = openMultiReader(indexes)) {
if (reader.numDocs() == 0) {
return new IndexSearchResult<>(Collections.emptyList(), false, 0);
}
BooleanQuery.Builder mainBuilder = new BooleanQuery.Builder();
Query chrQuery = new TermQuery(new Term(FeatureIndexFields.CHROMOSOME_ID.getFieldName(),
new BytesRef(chromosome.getId().toString())));
mainBuilder.add(chrQuery, BooleanClause.Occur.MUST);
BooleanQuery.Builder featureTypeBuilder = new BooleanQuery.Builder();
featureTypeBuilder.add(new TermQuery(new Term(FeatureIndexFields.FEATURE_TYPE.getFieldName(),
FeatureType.GENE.getFileValue())), BooleanClause.Occur.SHOULD);
featureTypeBuilder.add(new TermQuery(new Term(FeatureIndexFields.FEATURE_TYPE.getFieldName(),
FeatureType.EXON.getFileValue())), BooleanClause.Occur.SHOULD);
mainBuilder.add(featureTypeBuilder.build(), BooleanClause.Occur.MUST);
BooleanQuery.Builder rangeBuilder = new BooleanQuery.Builder();
//start in interval
Query startQuery =
IntPoint.newRangeQuery(FeatureIndexFields.START_INDEX.getFieldName(), start, end);
rangeBuilder.add(startQuery, BooleanClause.Occur.SHOULD);
//end in interval
Query endQuery =
IntPoint.newRangeQuery(FeatureIndexFields.END_INDEX.getFieldName(), start, end);
rangeBuilder.add(endQuery, BooleanClause.Occur.SHOULD);
//feature lasts along all the interval (start < range and end > range)
BooleanQuery.Builder spanQueryBuilder = new BooleanQuery.Builder();
Query startExtQuery =
IntPoint.newRangeQuery(FeatureIndexFields.START_INDEX.getFieldName(),
0, start - 1);
spanQueryBuilder.add(startExtQuery, BooleanClause.Occur.MUST);
Query endExtQuery =
IntPoint.newRangeQuery(FeatureIndexFields.END_INDEX.getFieldName(),
end + 1, Integer.MAX_VALUE);
spanQueryBuilder.add(endExtQuery, BooleanClause.Occur.MUST);
rangeBuilder.add(spanQueryBuilder.build(), BooleanClause.Occur.SHOULD);
mainBuilder.add(rangeBuilder.build(), BooleanClause.Occur.MUST);
return searchFileIndexes(files, mainBuilder.build(), null,
reader.numDocs(), null);
} finally {
for (SimpleFSDirectory index : indexes) {
IOUtils.closeQuietly(index);
}
}
}
示例6: test2Query
import org.apache.lucene.document.IntPoint; //导入方法依赖的package包/类
@Test
public void test2Query() throws IOException, ParseException {
IndexReader indexReader = DirectoryReader.open(directory);
StandardAnalyzer analyzer = new StandardAnalyzer();
QueryParser qp = new QueryParser("title", analyzer) {
@Override
protected Query getRangeQuery(final String fieldName, final String start, final String end, final boolean startInclusive,
final boolean endInclusive) throws ParseException {
if ("testIntField".equals(fieldName)) {
int startInt = Integer.parseInt(start);
int endInt = Integer.parseInt(end);
if (!startInclusive) {
startInt += 1;
}
if (!endInclusive) {
endInt -= 1;
}
return IntPoint.newRangeQuery(fieldName, startInt, endInt);
}
// return default
return super.getRangeQuery(fieldName, start, end, startInclusive, endInclusive);
}
@Override
protected Query newTermQuery(org.apache.lucene.index.Term term) {
String field = term.field();
String text = term.text();
if ("testIntField".equals(field)) {
int value = Integer.parseInt(text);
return IntPoint.newExactQuery(field, value);
}
return super.newTermQuery(term);
}
};
qp.setAllowLeadingWildcard(true);
int hits;
hits = runQuery(indexReader, qp, "java", 10);
assertEquals("Expected 2 hits", 2, hits);
hits = runQuery(indexReader, qp, "perl", 10);
assertEquals("Expected 0 hits", 0, hits);
hits = runQuery(indexReader, qp, "treatment", 10);
assertEquals("Expected 0 hits", 0, hits);
hits = runQuery(indexReader, qp, "long", 10);
assertEquals("Expected 2 hits", 2, hits);
hits = runQuery(indexReader, qp, "MongoDB", 10);
assertEquals("Expected 1 hit", 1, hits);
hits = runQuery(indexReader, qp, "java AND awesome", 10);
assertEquals("Expected 1 hit", 1, hits);
hits = runQuery(indexReader, qp, "testIntField:1", 10);
assertEquals("Expected 0 hits", 0, hits);
hits = runQuery(indexReader, qp, "testIntField:3", 10);
assertEquals("Expected 5 hits", 5, hits);
hits = runQuery(indexReader, qp, "testIntField:[1 TO 10]", 10);
assertEquals("Expected 5 hits", 5, hits);
indexReader.close();
}