use of org.apache.lucene.search.FieldValueQuery in project lucene-solr by apache.
the class TestJoinUtil method numericDocValuesScoreQuery.
// FunctionQuery would be helpful, but join module doesn't depend on queries module.
static Query numericDocValuesScoreQuery(final String field) {
return new Query() {
private final Query fieldQuery = new FieldValueQuery(field);
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
Weight fieldWeight = fieldQuery.createWeight(searcher, false, boost);
return new Weight(this) {
@Override
public void extractTerms(Set<Term> terms) {
}
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
return null;
}
@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
Scorer fieldScorer = fieldWeight.scorer(context);
if (fieldScorer == null) {
return null;
}
NumericDocValues price = context.reader().getNumericDocValues(field);
return new FilterScorer(fieldScorer, this) {
@Override
public float score() throws IOException {
assertEquals(in.docID(), price.advance(in.docID()));
return (float) price.longValue();
}
};
}
};
}
@Override
public String toString(String field) {
return fieldQuery.toString(field);
}
@Override
public boolean equals(Object o) {
return o == this;
}
@Override
public int hashCode() {
return System.identityHashCode(this);
}
};
}
use of org.apache.lucene.search.FieldValueQuery in project elasticsearch by elastic.
the class MaxAggregatorTests method testSomeMatchesNumericDocValues.
public void testSomeMatchesNumericDocValues() throws IOException {
testCase(new FieldValueQuery("number"), iw -> {
iw.addDocument(singleton(new NumericDocValuesField("number", 7)));
iw.addDocument(singleton(new NumericDocValuesField("number", 1)));
}, max -> {
assertEquals(7, max.getValue(), 0);
});
}
use of org.apache.lucene.search.FieldValueQuery in project elasticsearch by elastic.
the class ValueCountAggregatorTests method testSomeMatchesNumericDocValues.
public void testSomeMatchesNumericDocValues() throws IOException {
testCase(new FieldValueQuery(FIELD_NAME), ValueType.NUMBER, iw -> {
iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 7)));
iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 1)));
}, count -> assertEquals(2L, count.getValue()));
}
use of org.apache.lucene.search.FieldValueQuery in project lucene-solr by apache.
the class CurrencyValue method getRangeQuery.
public Query getRangeQuery(QParser parser, SchemaField field, final CurrencyValue p1, final CurrencyValue p2, final boolean minInclusive, final boolean maxInclusive) {
String currencyCode = (p1 != null) ? p1.getCurrencyCode() : (p2 != null) ? p2.getCurrencyCode() : defaultCurrency;
// ValueSourceRangeFilter doesn't check exists(), so we have to
final Filter docsWithValues = new QueryWrapperFilter(new FieldValueQuery(getAmountField(field).getName()));
final Filter vsRangeFilter = new ValueSourceRangeFilter(new RawCurrencyValueSource(field, currencyCode, parser), p1 == null ? null : p1.getAmount() + "", p2 == null ? null : p2.getAmount() + "", minInclusive, maxInclusive);
final BooleanQuery.Builder docsInRange = new BooleanQuery.Builder();
docsInRange.add(docsWithValues, Occur.FILTER);
docsInRange.add(vsRangeFilter, Occur.FILTER);
return new SolrConstantScoreQuery(new QueryWrapperFilter(docsInRange.build()));
}
Aggregations