Search in sources :

Example 1 with LegacyNumericRangeQuery

use of org.apache.solr.legacy.LegacyNumericRangeQuery in project lucene-solr by apache.

the class TestLegacyNumericRangeQueryBuilder method testGetFilterLong.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void testGetFilterLong() throws Exception {
    LegacyNumericRangeQueryBuilder filterBuilder = new LegacyNumericRangeQueryBuilder();
    String xml = "<LegacyNumericRangeQuery fieldName='AGE' type='LoNg' lowerTerm='-2321' upperTerm='60000000'/>";
    Document doc = getDocumentFromString(xml);
    Query filter = filterBuilder.getQuery(doc.getDocumentElement());
    assertTrue(filter instanceof LegacyNumericRangeQuery<?>);
    LegacyNumericRangeQuery<Long> numRangeFilter = (LegacyNumericRangeQuery) filter;
    assertEquals(Long.valueOf(-2321L), numRangeFilter.getMin());
    assertEquals(Long.valueOf(60000000L), numRangeFilter.getMax());
    assertEquals("AGE", numRangeFilter.getField());
    assertTrue(numRangeFilter.includesMin());
    assertTrue(numRangeFilter.includesMax());
    String xml2 = "<LegacyNumericRangeQuery fieldName='AGE' type='LoNg' lowerTerm='-2321' upperTerm='60000000' includeUpper='false'/>";
    Document doc2 = getDocumentFromString(xml2);
    Query filter2 = filterBuilder.getQuery(doc2.getDocumentElement());
    assertTrue(filter2 instanceof LegacyNumericRangeQuery<?>);
    LegacyNumericRangeQuery<Long> numRangeFilter2 = (LegacyNumericRangeQuery) filter2;
    assertEquals(Long.valueOf(-2321L), numRangeFilter2.getMin());
    assertEquals(Long.valueOf(60000000L), numRangeFilter2.getMax());
    assertEquals("AGE", numRangeFilter2.getField());
    assertTrue(numRangeFilter2.includesMin());
    assertFalse(numRangeFilter2.includesMax());
}
Also used : LegacyNumericRangeQuery(org.apache.solr.legacy.LegacyNumericRangeQuery) Query(org.apache.lucene.search.Query) LegacyNumericRangeQuery(org.apache.solr.legacy.LegacyNumericRangeQuery) Document(org.w3c.dom.Document)

Example 2 with LegacyNumericRangeQuery

use of org.apache.solr.legacy.LegacyNumericRangeQuery in project lucene-solr by apache.

the class TestLegacyNumericRangeQueryBuilder method testGetFilterInt.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void testGetFilterInt() throws Exception {
    LegacyNumericRangeQueryBuilder filterBuilder = new LegacyNumericRangeQueryBuilder();
    String xml = "<LegacyNumericRangeQuery fieldName='AGE' type='int' lowerTerm='-1' upperTerm='10'/>";
    Document doc = getDocumentFromString(xml);
    Query filter = filterBuilder.getQuery(doc.getDocumentElement());
    assertTrue(filter instanceof LegacyNumericRangeQuery<?>);
    LegacyNumericRangeQuery<Integer> numRangeFilter = (LegacyNumericRangeQuery<Integer>) filter;
    assertEquals(Integer.valueOf(-1), numRangeFilter.getMin());
    assertEquals(Integer.valueOf(10), numRangeFilter.getMax());
    assertEquals("AGE", numRangeFilter.getField());
    assertTrue(numRangeFilter.includesMin());
    assertTrue(numRangeFilter.includesMax());
    String xml2 = "<LegacyNumericRangeQuery fieldName='AGE' type='int' lowerTerm='-1' upperTerm='10' includeUpper='false'/>";
    Document doc2 = getDocumentFromString(xml2);
    Query filter2 = filterBuilder.getQuery(doc2.getDocumentElement());
    assertTrue(filter2 instanceof LegacyNumericRangeQuery<?>);
    LegacyNumericRangeQuery<Integer> numRangeFilter2 = (LegacyNumericRangeQuery) filter2;
    assertEquals(Integer.valueOf(-1), numRangeFilter2.getMin());
    assertEquals(Integer.valueOf(10), numRangeFilter2.getMax());
    assertEquals("AGE", numRangeFilter2.getField());
    assertTrue(numRangeFilter2.includesMin());
    assertFalse(numRangeFilter2.includesMax());
}
Also used : LegacyNumericRangeQuery(org.apache.solr.legacy.LegacyNumericRangeQuery) Query(org.apache.lucene.search.Query) LegacyNumericRangeQuery(org.apache.solr.legacy.LegacyNumericRangeQuery) Document(org.w3c.dom.Document)

Example 3 with LegacyNumericRangeQuery

use of org.apache.solr.legacy.LegacyNumericRangeQuery in project lucene-solr by apache.

the class TestLegacyNumericRangeQueryBuilder method testGetFilterFloat.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void testGetFilterFloat() throws Exception {
    LegacyNumericRangeQueryBuilder filterBuilder = new LegacyNumericRangeQueryBuilder();
    String xml = "<LegacyNumericRangeQuery fieldName='AGE' type='FLOAT' lowerTerm='-2.321432' upperTerm='32432.23'/>";
    Document doc = getDocumentFromString(xml);
    Query filter = filterBuilder.getQuery(doc.getDocumentElement());
    assertTrue(filter instanceof LegacyNumericRangeQuery<?>);
    LegacyNumericRangeQuery<Float> numRangeFilter = (LegacyNumericRangeQuery) filter;
    assertEquals(Float.valueOf(-2.321432f), numRangeFilter.getMin());
    assertEquals(Float.valueOf(32432.23f), numRangeFilter.getMax());
    assertEquals("AGE", numRangeFilter.getField());
    assertTrue(numRangeFilter.includesMin());
    assertTrue(numRangeFilter.includesMax());
    String xml2 = "<LegacyNumericRangeQuery fieldName='AGE' type='FLOAT' lowerTerm='-2.321432' upperTerm='32432.23' includeUpper='false' precisionStep='2' />";
    Document doc2 = getDocumentFromString(xml2);
    Query filter2 = filterBuilder.getQuery(doc2.getDocumentElement());
    assertTrue(filter2 instanceof LegacyNumericRangeQuery<?>);
    LegacyNumericRangeQuery<Float> numRangeFilter2 = (LegacyNumericRangeQuery) filter2;
    assertEquals(Float.valueOf(-2.321432f), numRangeFilter2.getMin());
    assertEquals(Float.valueOf(32432.23f), numRangeFilter2.getMax());
    assertEquals("AGE", numRangeFilter2.getField());
    assertTrue(numRangeFilter2.includesMin());
    assertFalse(numRangeFilter2.includesMax());
}
Also used : LegacyNumericRangeQuery(org.apache.solr.legacy.LegacyNumericRangeQuery) Query(org.apache.lucene.search.Query) LegacyNumericRangeQuery(org.apache.solr.legacy.LegacyNumericRangeQuery) Document(org.w3c.dom.Document)

Example 4 with LegacyNumericRangeQuery

use of org.apache.solr.legacy.LegacyNumericRangeQuery in project lucene-solr by apache.

the class TestLegacyNumericRangeQueryBuilder method testGetFilterDouble.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void testGetFilterDouble() throws Exception {
    LegacyNumericRangeQueryBuilder filterBuilder = new LegacyNumericRangeQueryBuilder();
    String xml = "<LegacyNumericRangeQuery fieldName='AGE' type='doubLe' lowerTerm='-23.21' upperTerm='60000.00023'/>";
    Document doc = getDocumentFromString(xml);
    Query filter = filterBuilder.getQuery(doc.getDocumentElement());
    assertTrue(filter instanceof LegacyNumericRangeQuery<?>);
    LegacyNumericRangeQuery<Double> numRangeFilter = (LegacyNumericRangeQuery) filter;
    assertEquals(Double.valueOf(-23.21d), numRangeFilter.getMin());
    assertEquals(Double.valueOf(60000.00023d), numRangeFilter.getMax());
    assertEquals("AGE", numRangeFilter.getField());
    assertTrue(numRangeFilter.includesMin());
    assertTrue(numRangeFilter.includesMax());
    String xml2 = "<LegacyNumericRangeQuery fieldName='AGE' type='doubLe' lowerTerm='-23.21' upperTerm='60000.00023' includeUpper='false'/>";
    Document doc2 = getDocumentFromString(xml2);
    Query filter2 = filterBuilder.getQuery(doc2.getDocumentElement());
    assertTrue(filter2 instanceof LegacyNumericRangeQuery<?>);
    LegacyNumericRangeQuery<Double> numRangeFilter2 = (LegacyNumericRangeQuery) filter2;
    assertEquals(Double.valueOf(-23.21d), numRangeFilter2.getMin());
    assertEquals(Double.valueOf(60000.00023d), numRangeFilter2.getMax());
    assertEquals("AGE", numRangeFilter2.getField());
    assertTrue(numRangeFilter2.includesMin());
    assertFalse(numRangeFilter2.includesMax());
}
Also used : LegacyNumericRangeQuery(org.apache.solr.legacy.LegacyNumericRangeQuery) Query(org.apache.lucene.search.Query) LegacyNumericRangeQuery(org.apache.solr.legacy.LegacyNumericRangeQuery) Document(org.w3c.dom.Document)

Example 5 with LegacyNumericRangeQuery

use of org.apache.solr.legacy.LegacyNumericRangeQuery in project lucene-solr by apache.

the class TestMaxScoreQueryParser method testFallbackToLucene.

@Test
public void testFallbackToLucene() {
    q = parse("foo");
    assertEquals(new TermQuery(new Term("text", "foo")), q);
    q = parse("foo^3.0");
    assertEquals(new BoostQuery(new TermQuery(new Term("text", "foo")), 3f), q);
    q = parse("price:[0 TO 10]");
    assertTrue(q instanceof LegacyNumericRangeQuery || (q instanceof IndexOrDocValuesQuery && ((IndexOrDocValuesQuery) q).getIndexQuery() instanceof PointRangeQuery));
}
Also used : LegacyNumericRangeQuery(org.apache.solr.legacy.LegacyNumericRangeQuery) Term(org.apache.lucene.index.Term) Test(org.junit.Test)

Aggregations

LegacyNumericRangeQuery (org.apache.solr.legacy.LegacyNumericRangeQuery)6 Query (org.apache.lucene.search.Query)5 Document (org.w3c.dom.Document)4 Term (org.apache.lucene.index.Term)2 BooleanClause (org.apache.lucene.search.BooleanClause)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 BoostQuery (org.apache.lucene.search.BoostQuery)1 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)1 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)1 PrefixQuery (org.apache.lucene.search.PrefixQuery)1 TermQuery (org.apache.lucene.search.TermQuery)1 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)1 WildcardQuery (org.apache.lucene.search.WildcardQuery)1 BytesRef (org.apache.lucene.util.BytesRef)1 FieldType (org.apache.solr.schema.FieldType)1 Test (org.junit.Test)1