private NodeNumericRangeQueryBuilder(final String field, final int precisionStep, final Double min, final Double max, final boolean minInclusive, final boolean maxInclusive) { nmq = NodeNumericRangeQuery .newDoubleRange(field, precisionStep, min, max, minInclusive, maxInclusive); }
private NodeNumericRangeQueryBuilder(final String field, final int precisionStep, final Float min, final Float max, final boolean minInclusive, final boolean maxInclusive) { nmq = NodeNumericRangeQuery .newFloatRange(field, precisionStep, min, max, minInclusive, maxInclusive); }
private NodeNumericRangeQueryBuilder(final String field, final int precisionStep, final Integer min, final Integer max, final boolean minInclusive, final boolean maxInclusive) { nmq = NodeNumericRangeQuery .newIntRange(field, precisionStep, min, max, minInclusive, maxInclusive); }
@Override public String toString(final String field) { final StringBuffer sb = new StringBuffer(); sb.append(minInclusive ? '[' : '{') .append((min == null) ? "*" : min.toString()) .append(" TO ") .append((max == null) ? "*" : max.toString()) .append(maxInclusive ? ']' : '}') .append(ToStringUtils.boost(this.getBoost())); return this.wrapToStringWithDatatype(sb).toString(); }
return NodeNumericRangeQuery.newLongRange(field, precisionStep, (Long) lowerNumber, (Long) upperNumber, minInclusive, maxInclusive); return NodeNumericRangeQuery.newIntRange(field, precisionStep, (Integer) lowerNumber, (Integer) upperNumber, minInclusive, maxInclusive); return NodeNumericRangeQuery.newFloatRange(field, precisionStep, (Float) lowerNumber, (Float) upperNumber, minInclusive, maxInclusive); return NodeNumericRangeQuery.newDoubleRange(field, precisionStep, (Double) lowerNumber, (Double) upperNumber, minInclusive, maxInclusive);
@Test public void testEqualsAndHash() throws Exception { QueryUtils.checkHashEquals(NodeNumericRangeQuery.newIntRange("test1", 4, 10, 20, true, true)); QueryUtils.checkHashEquals(NodeNumericRangeQuery.newIntRange("test2", 4, 10, 20, false, true)); QueryUtils.checkHashEquals(NodeNumericRangeQuery.newIntRange("test3", 4, 10, 20, true, false)); QueryUtils.checkHashEquals(NodeNumericRangeQuery.newIntRange("test4", 4, 10, 20, false, false)); QueryUtils.checkHashEquals(NodeNumericRangeQuery.newIntRange("test5", 4, 10, null, true, true)); QueryUtils.checkHashEquals(NodeNumericRangeQuery.newIntRange("test6", 4, null, 20, true, true)); QueryUtils.checkHashEquals(NodeNumericRangeQuery.newIntRange("test7", 4, null, null, true, true)); QueryUtils.checkEqual( NodeNumericRangeQuery.newIntRange("test8", 4, 10, 20, true, true), NodeNumericRangeQuery.newIntRange("test8", 4, 10, 20, true, true) ); QueryUtils.checkUnequal( NodeNumericRangeQuery.newIntRange("test9", 4, 10, 20, true, true), NodeNumericRangeQuery.newIntRange("test9", 8, 10, 20, true, true) ); QueryUtils.checkUnequal( NodeNumericRangeQuery.newIntRange("test10a", 4, 10, 20, true, true), NodeNumericRangeQuery.newIntRange("test10b", 4, 10, 20, true, true) ); QueryUtils.checkUnequal( NodeNumericRangeQuery.newIntRange("test11", 4, 10, 20, true, true), NodeNumericRangeQuery.newIntRange("test11", 4, 20, 10, true, true) ); QueryUtils.checkUnequal( NodeNumericRangeQuery.newIntRange("test12", 4, 10, 20, true, true), NodeNumericRangeQuery.newIntRange("test12", 4, 10, 20, false, true) ); QueryUtils.checkUnequal(
@Test public void testEqualsAndHash() throws Exception { QueryUtils.checkHashEquals(NodeNumericRangeQuery.newLongRange("test1", 4, 10L, 20L, true, true)); QueryUtils.checkHashEquals(NodeNumericRangeQuery.newLongRange("test2", 4, 10L, 20L, false, true)); QueryUtils.checkHashEquals(NodeNumericRangeQuery.newLongRange("test3", 4, 10L, 20L, true, false)); QueryUtils.checkHashEquals(NodeNumericRangeQuery.newLongRange("test4", 4, 10L, 20L, false, false)); QueryUtils.checkHashEquals(NodeNumericRangeQuery.newLongRange("test5", 4, 10L, null, true, true)); QueryUtils.checkHashEquals(NodeNumericRangeQuery.newLongRange("test6", 4, null, 20L, true, true)); QueryUtils.checkHashEquals(NodeNumericRangeQuery.newLongRange("test7", 4, null, null, true, true)); QueryUtils.checkEqual( NodeNumericRangeQuery.newLongRange("test8", 4, 10L, 20L, true, true), NodeNumericRangeQuery.newLongRange("test8", 4, 10L, 20L, true, true) ); QueryUtils.checkUnequal( NodeNumericRangeQuery.newLongRange("test9", 4, 10L, 20L, true, true), NodeNumericRangeQuery.newLongRange("test9", 8, 10L, 20L, true, true) ); QueryUtils.checkUnequal( NodeNumericRangeQuery.newLongRange("test10a", 4, 10L, 20L, true, true), NodeNumericRangeQuery.newLongRange("test10b", 4, 10L, 20L, true, true) ); QueryUtils.checkUnequal( NodeNumericRangeQuery.newLongRange("test11", 4, 10L, 20L, true, true), NodeNumericRangeQuery.newLongRange("test11", 4, 20L, 10L, true, true) ); QueryUtils.checkUnequal( NodeNumericRangeQuery.newLongRange("test12", 4, 10L, 20L, true, true), NodeNumericRangeQuery.newLongRange("test12", 4, 10L, 20L, false, true) ); QueryUtils.checkUnequal(
@Test public void testQNameInDatatype() throws Exception { final String qnames = "./src/test/resources/conf/qnames"; final HashMap<ConfigurationKey, Object> config = new HashMap<ConfigurationKey, Object>(); config.put(KeywordConfigurationKeys.QNAMES, this.loadQNamesFile(qnames)); final Map<String, Analyzer> dts = new HashMap<String, Analyzer>(); dts.put(XSDDatatype.XSD_LONG, new LongNumericAnalyzer(4)); config.put(KeywordConfigurationKeys.DATATYPES_ANALYZERS, dts); final NodeNumericRangeQuery q = NodeNumericRangeQuery.newLongRange(SirenTestCase.DEFAULT_TEST_FIELD, 4, 50l, 60l, true, false); q.setDatatype(XSDDatatype.XSD_LONG); this._assertSirenQuery(config, new LuceneProxyNodeQuery(q), "xsd:long([50 TO 60})"); }
private NodeNumericRangeQueryBuilder(final String field, final int precisionStep, final Long min, final Long max, final boolean minInclusive, final boolean maxInclusive) { nmq = NodeNumericRangeQuery .newLongRange(field, precisionStep, min, max, minInclusive, maxInclusive); }
public NodeNumericRangeQueryBuilder setRewriteMethod(final RewriteMethod method) { nmq.setRewriteMethod(method); return this; }
/** * Factory that creates a <code>SirenNumericRangeQuery</code>, that queries a <code>long</code> * range using the given <a href="#precisionStepDesc"><code>precisionStep</code></a>. * You can have half-open ranges (which are in fact </≤ or >/≥ queries) * by setting the min or max value to <code>null</code>. By setting inclusive to false, it will * match all documents excluding the bounds, with inclusive on, the boundaries are hits, too. */ public static NodeNumericRangeQuery<Long> newLongRange(final String field, final int precisionStep, final Long min, final Long max, final boolean minInclusive, final boolean maxInclusive) { return new NodeNumericRangeQuery<Long>(field, precisionStep, NumericType.LONG, min, max, minInclusive, maxInclusive); }
@Override public NodeQueryBuilder setDatatype(final String datatype) { nmq.setDatatype(datatype); return this; }
.newIntRange(SirenTestCase.DEFAULT_TEST_FIELD, 4, null, 10, true, true); openLeft.setDatatype(datatype); openRight = NodeNumericRangeQuery .newIntRange(SirenTestCase.DEFAULT_TEST_FIELD, 4, 10, null, true, true); openRight.setDatatype(datatype); } else if (datatype.equals("float4")) { openLeft = NodeNumericRangeQuery .newFloatRange(SirenTestCase.DEFAULT_TEST_FIELD, 4, null, 10f, true, true); openLeft.setDatatype(datatype); openRight = NodeNumericRangeQuery .newFloatRange(SirenTestCase.DEFAULT_TEST_FIELD, 4, 10f, null, true, true); openRight.setDatatype(datatype); } else if (datatype.equals("long4")) { openLeft = NodeNumericRangeQuery .newLongRange(SirenTestCase.DEFAULT_TEST_FIELD, 4, null, 10l, true, true); openLeft.setDatatype(datatype); openRight = NodeNumericRangeQuery .newLongRange(SirenTestCase.DEFAULT_TEST_FIELD, 4, 10l, null, true, true); openRight.setDatatype(datatype); } else { openLeft = NodeNumericRangeQuery .newDoubleRange(SirenTestCase.DEFAULT_TEST_FIELD, 4, null, 10d, true, true); openLeft.setDatatype(datatype); openRight = NodeNumericRangeQuery .newDoubleRange(SirenTestCase.DEFAULT_TEST_FIELD, 4, 10d, null, true, true); openRight.setDatatype(datatype);
this.setRewriteMethod(CONSTANT_SCORE_AUTO_REWRITE_DEFAULT); break; case INT: this.setRewriteMethod(CONSTANT_SCORE_AUTO_REWRITE_DEFAULT); break; default: this.setRewriteMethod(CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
/** * Factory that creates a <code>SirenNumericRangeQuery</code>, that queries a <code>double</code> * range using the given <a href="#precisionStepDesc"><code>precisionStep</code></a>. * You can have half-open ranges (which are in fact </≤ or >/≥ queries) * by setting the min or max value to <code>null</code>. By setting inclusive to false, it will * match all documents excluding the bounds, with inclusive on, the boundaries are hits, too. */ public static NodeNumericRangeQuery<Double> newDoubleRange(final String field, final int precisionStep, final Double min, final Double max, final boolean minInclusive, final boolean maxInclusive) { return new NodeNumericRangeQuery<Double>(field, precisionStep, NumericType.DOUBLE, min, max, minInclusive, maxInclusive); }
@Test(expected=AssertionError.class) public void testNumericDatatypeWrongPrecision() throws Exception { final KeywordQueryParser parser = new KeywordQueryParser(); // Set the default datatypes final Map<String, Analyzer> datatypes = new HashMap<String, Analyzer>(); datatypes.put("int", new IntNumericAnalyzer(4)); parser.setDatatypeAnalyzers(datatypes); final NodeQuery rangeWrong = NodeNumericRangeQuery.newIntRange(SirenTestCase.DEFAULT_TEST_FIELD, 42, 12, 21, true, true); assertEquals(new LuceneProxyNodeQuery(rangeWrong), parser.parse("int([12 TO 21])", SirenTestCase.DEFAULT_TEST_FIELD)); }
/** * Test for float. * <p> * Numeric ranges get processed with {@link NodeNumericRangeQueryNodeProcessor}. * Single numeric values are processed with {@link NodeNumericQueryNodeProcessor}. */ @Test public void testNumericQuery4() throws Exception { final HashMap<ConfigurationKey, Object> config = new HashMap<ConfigurationKey, Object>(); final Map<String, Analyzer> datatypes = new HashMap<String, Analyzer>(); datatypes.put("float", new FloatNumericAnalyzer(4)); config.put(KeywordConfigurationKeys.DATATYPES_ANALYZERS, datatypes); final NodePrimitiveQuery q = NodeNumericRangeQuery .newFloatRange(SirenTestCase.DEFAULT_TEST_FIELD, 4, 50.5f, 1000.34f, true, true); q.setDatatype("float"); this._assertSirenQuery(config, new LuceneProxyNodeQuery(q), "float([50.5 TO 1000.34])"); }
/** * Factory that creates a <code>SirenNumericRangeQuery</code>, that queries a <code>long</code> * range using the default <code>precisionStep</code> {@link NumericUtils#PRECISION_STEP_DEFAULT} (4). * You can have half-open ranges (which are in fact </≤ or >/≥ queries) * by setting the min or max value to <code>null</code>. By setting inclusive to false, it will * match all documents excluding the bounds, with inclusive on, the boundaries are hits, too. */ public static NodeNumericRangeQuery<Long> newLongRange(final String field, final Long min, final Long max, final boolean minInclusive, final boolean maxInclusive) { return new NodeNumericRangeQuery<Long>(field, NumericUtils.PRECISION_STEP_DEFAULT, NumericType.LONG, min, max, minInclusive, maxInclusive); }
/** * Boolean of ranges. * <p> * Numeric ranges get processed with {@link NodeNumericRangeQueryNodeProcessor}. * Single numeric values are processed with {@link NodeNumericQueryNodeProcessor}. */ @Test public void testNumericQuery3() throws Exception { final HashMap<ConfigurationKey, Object> config = new HashMap<ConfigurationKey, Object>(); final Map<String, Analyzer> datatypes = new HashMap<String, Analyzer>(); datatypes.put("int", new IntNumericAnalyzer(4)); config.put(KeywordConfigurationKeys.DATATYPES_ANALYZERS, datatypes); config.put(ConfigurationKeys.DEFAULT_OPERATOR, Operator.OR); final NodePrimitiveQuery r1 = NodeNumericRangeQuery .newIntRange(SirenTestCase.DEFAULT_TEST_FIELD, 4, 50, 100, true, true); r1.setDatatype("int"); final NodePrimitiveQuery r2 = NodeNumericRangeQuery .newIntRange(SirenTestCase.DEFAULT_TEST_FIELD, 4, 100, 500, true, true); r2.setDatatype("int"); final BooleanQuery bq = new BooleanQuery(); bq.add(new LuceneProxyNodeQuery(r1), BooleanClause.Occur.SHOULD); bq.add(new LuceneProxyNodeQuery(r2), BooleanClause.Occur.SHOULD); this._assertSirenQuery(config, bq, "int([50 TO 100] OR [100 TO 500])"); }
/** * Factory that creates a <code>SirenNumericRangeQuery</code>, that queries a <code>int</code> * range using the given <a href="#precisionStepDesc"><code>precisionStep</code></a>. * You can have half-open ranges (which are in fact </≤ or >/≥ queries) * by setting the min or max value to <code>null</code>. By setting inclusive to false, it will * match all documents excluding the bounds, with inclusive on, the boundaries are hits, too. */ public static NodeNumericRangeQuery<Integer> newIntRange(final String field, final int precisionStep, final Integer min, final Integer max, final boolean minInclusive, final boolean maxInclusive) { return new NodeNumericRangeQuery<Integer>(field, precisionStep, NumericType.INT, min, max, minInclusive, maxInclusive); }