.must(new TermQuery(new Term("siteId", siteId.toString()))); if (null != startPublishDate) { termination.must(queryBuilder.range().onField("publishDate").above(startPublishDate).createQuery());
.must(new TermQuery(new Term("siteId", siteId.toString()))); if (null != startPublishDate) { termination.must(queryBuilder.range().onField("publishDate").above(startPublishDate).createQuery());
.must(new TermQuery(new Term("siteId", siteId.toString()))); if (null != startPublishDate) { termination.must(queryBuilder.range().onField("publishDate").above(startPublishDate).createQuery());
.must(new TermQuery(new Term("siteId", siteId.toString()))); if (null != startPublishDate) { termination.must(queryBuilder.range().onField("publishDate").above(startPublishDate).createQuery());
@Override protected Query getGreaterOrEqualsQuery() { return matchingContextSupport.rangeMatchingContext().above( value ).createQuery(); }
@Override protected Query getStrictlyGreaterQuery() { return matchingContextSupport.rangeMatchingContext().above( value ).excludeLimit().createQuery(); } }
@Test public void testRangeQueryAbove() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); calendar.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); calendar.set( 10 + 1900, 2, 12, 0, 0, 0 ); Date to = calendar.getTime(); Query query = monthQb .range() .onField( "estimatedCreation" ) .andField( "justfortest" ) .ignoreFieldBridge().ignoreAnalyzer() .above( to ) .createQuery(); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 2 ); }
@Test @Category(SkipOnElasticsearch.class) // This only works because of a Lucene-specific hack in org.hibernate.search.bridge.util.impl.NumericFieldUtils.createNumericRangeQuery public void testRangeQueryAboveIgnoreFieldBridge() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); calendar.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); calendar.set( 10 + 1900, 2, 12, 0, 0, 0 ); Date to = calendar.getTime(); Query query = monthQb .range() .onField( "estimatedCreation" ) .ignoreFieldBridge() .andField( "justfortest" ) .ignoreFieldBridge().ignoreAnalyzer() .above( DateTools.round( to, DateTools.Resolution.MINUTE ) ) .createQuery(); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 2 ); }
@Test @TestForIssue(jiraKey = "HSEARCH-2070") public void testSearchDateWithoutFieldBridge() throws Exception { QueryBuilder qb = helper.queryBuilder( ContainerEntity.class ); Query q = qb.range().onField( "emb.date" ) .above( initCalendar( 2007, Calendar.JANUARY, 14 ).getTime() ) .createQuery(); assertQuery( q ).matchesExactlyIds( 1L ); }
@Test @TestForIssue( jiraKey = "HSEARCH-1378") public void testNumericRangeQueryAbove() { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); //inclusive Query query = monthQb .range() .onField( "raindropInMm" ) .above( 0.231d ) .createQuery(); assertTrue( query.getClass().isAssignableFrom( NumericRangeQuery.class ) ); helper.assertThat( query ).from( Month.class ).matchesUnorderedIds( 1, 2, 3 ); //exclusive query = monthQb .range() .onField( "raindropInMm" ) .above( 0.231d ) .excludeLimit() .createQuery(); helper.assertThat( query ).from( Month.class ).matchesUnorderedIds( 2, 3 ); }
@Test public void testNumericFieldWithBigDecimals() throws Exception { Session session = openSession(); Transaction tx = session.beginTransaction(); // create entities Item item = new Item(); item.setPrice( new BigDecimal( 154.34 ) ); session.save( item ); tx.commit(); tx = session.beginTransaction(); FullTextSession fullTextSession = Search.getFullTextSession( session ); QueryBuilder queryBuilder = fullTextSession.getSearchFactory() .buildQueryBuilder() .forEntity( Item.class ) .get(); Query rootQuery = queryBuilder.bool() .must( queryBuilder.range().onField( "price" ).above( 10000L ).createQuery() ) .must( queryBuilder.range().onField( "price" ).below( 20000L ).createQuery() ) .createQuery(); @SuppressWarnings( "unchecked" ) List<Item> resultList = fullTextSession.createFullTextQuery( rootQuery, Item.class ).list(); assertNotNull( resultList ); assertEquals( 1, resultList.size() ); tx.commit(); session.close(); }
public void testQueryingRangeAboveExcludingLimit() throws ParseException { loadTestingData(); Query query = Search.getSearchManager(cache).buildQueryBuilderForClass(Person.class) .get().range().onField("age").above(30).excludeLimit().createQuery(); CacheQuery<?> cacheQuery = Search.getSearchManager(cache).getQuery(query); List<?> found = cacheQuery.list(); assertEquals(0, found.size()); query = Search.getSearchManager(cache).buildQueryBuilderForClass(Person.class) .get().range().onField("age").above(20).excludeLimit().createQuery(); cacheQuery = Search.getSearchManager(cache).getQuery(query); found = cacheQuery.list(); assertEquals(2, found.size()); assert found.contains(person2); assert found.contains(person3); assert !found.contains(person4) : "This should not contain object person4"; person4 = new Person(); person4.setName("Mighty Goat"); person4.setBlurb("Also eats grass"); person4.setAge(28); cache.put("mighty", person4); cacheQuery = Search.getSearchManager(cache).getQuery(query); found = cacheQuery.list(); assert found.size() == 3 : "Size of list should be 3"; assert found.contains(person2); assert found.contains(person3); assert found.contains(person4) : "This should now contain object person4"; }
@SuppressWarnings("unchecked") private List<ArrayBridgeTestEntity> findResultsWithRangeQuery(String fieldName, Object start) { QueryBuilder queryBuilder = fullTextSession.getSearchFactory().buildQueryBuilder() .forEntity( ArrayBridgeTestEntity.class ).get(); Query query = queryBuilder.range().onField( fieldName ).above( start ).createQuery(); return fullTextSession.createFullTextQuery( query, ArrayBridgeTestEntity.class ).list(); }
@SuppressWarnings("unchecked") private List<IterableBridgeTestEntity> findResultsWithRangeQuery(String fieldName, Object start) { QueryBuilder queryBuilder = fullTextSession.getSearchFactory().buildQueryBuilder() .forEntity( IterableBridgeTestEntity.class ).get(); Query query = queryBuilder.range().onField( fieldName ).above( start ).createQuery(); return fullTextSession.createFullTextQuery( query, IterableBridgeTestEntity.class ).list(); }
@SuppressWarnings("unchecked") private List<MapBridgeTestEntity> findResultsWithRangeQuery(String fieldName, Object start) { QueryBuilder queryBuilder = fullTextSession.getSearchFactory().buildQueryBuilder() .forEntity( MapBridgeTestEntity.class ).get(); Query query = queryBuilder.range().onField( fieldName ).above( start ).createQuery(); return fullTextSession.createFullTextQuery( query, MapBridgeTestEntity.class ).list(); }
@Test public void testRangeQueryAboveInclusive() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); // test the limits, inclusive Query query = monthQb .range() .onField( "estimatedCreation" ) .andField( "justfortest" ) .ignoreFieldBridge().ignoreAnalyzer() .above( february ) .createQuery(); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 2 ); }
@Test public void testRangeQueryAboveExclusive() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); // test the limits, exclusive Query query = monthQb .range() .onField( "estimatedCreation" ) .andField( "justfortest" ) .ignoreFieldBridge().ignoreAnalyzer() .above( february ).excludeLimit() .createQuery(); helper.assertThat( query ).from( Month.class ).matchesNone(); }
@Override public Query visit(FullTextRangeExpr fullTextRangeExpr) { PropertyValueExpr propertyValueExpr = (PropertyValueExpr) fullTextRangeExpr.getChild(); //todo [anistor] incomplete implementation ? if (fullTextRangeExpr.getLower() == null && fullTextRangeExpr.getUpper() == null) { return new TermRangeQuery(propertyValueExpr.getPropertyPath().asStringPath(), null, null, fullTextRangeExpr.isIncludeLower(), fullTextRangeExpr.isIncludeUpper()); } RangeMatchingContext rangeMatchingContext = applyFieldBridge(true, propertyValueExpr.getPropertyPath(), queryBuilder.range().onField(propertyValueExpr.getPropertyPath().asStringPath())); RangeTerminationExcludable t = null; if (fullTextRangeExpr.getLower() != null) { t = rangeMatchingContext.above(fullTextRangeExpr.getLower()); if (!fullTextRangeExpr.isIncludeLower()) { t.excludeLimit(); } } if (fullTextRangeExpr.getUpper() != null) { t = rangeMatchingContext.below(fullTextRangeExpr.getUpper()); if (!fullTextRangeExpr.isIncludeUpper()) { t.excludeLimit(); } } return t.createQuery(); }
@Override public Query visit(FullTextRangeExpr fullTextRangeExpr) { PropertyValueExpr propertyValueExpr = (PropertyValueExpr) fullTextRangeExpr.getChild(); //todo [anistor] incomplete implementation ? if (fullTextRangeExpr.getLower() == null && fullTextRangeExpr.getUpper() == null) { return new TermRangeQuery(propertyValueExpr.getPropertyPath().asStringPath(), null, null, fullTextRangeExpr.isIncludeLower(), fullTextRangeExpr.isIncludeUpper()); } RangeMatchingContext rangeMatchingContext = applyFieldBridge(true, propertyValueExpr.getPropertyPath(), queryBuilder.range().onField(propertyValueExpr.getPropertyPath().asStringPath())); RangeTerminationExcludable t = null; if (fullTextRangeExpr.getLower() != null) { t = rangeMatchingContext.above(fullTextRangeExpr.getLower()); if (!fullTextRangeExpr.isIncludeLower()) { t.excludeLimit(); } } if (fullTextRangeExpr.getUpper() != null) { t = rangeMatchingContext.below(fullTextRangeExpr.getUpper()); if (!fullTextRangeExpr.isIncludeUpper()) { t.excludeLimit(); } } return t.createQuery(); }
@Override public Query visit(ComparisonExpr comparisonExpr) { PropertyValueExpr propertyValueExpr = (PropertyValueExpr) comparisonExpr.getLeftChild(); ConstantValueExpr constantValueExpr = (ConstantValueExpr) comparisonExpr.getRightChild(); Comparable value = constantValueExpr.getConstantValueAs(propertyValueExpr.getPrimitiveType(), namedParameters); switch (comparisonExpr.getComparisonType()) { case NOT_EQUAL: Query q = applyFieldBridge(false, propertyValueExpr.getPropertyPath(), queryBuilder.keyword().onField(propertyValueExpr.getPropertyPath().asStringPath())) .matching(value).createQuery(); return queryBuilder.bool().must(q).not().createQuery(); case EQUAL: return applyFieldBridge(false, propertyValueExpr.getPropertyPath(), queryBuilder.keyword().onField(propertyValueExpr.getPropertyPath().asStringPath())) .matching(value).createQuery(); case LESS: return applyFieldBridge(false, propertyValueExpr.getPropertyPath(), queryBuilder.range().onField(propertyValueExpr.getPropertyPath().asStringPath())) .below(value).excludeLimit().createQuery(); case LESS_OR_EQUAL: return applyFieldBridge(false, propertyValueExpr.getPropertyPath(), queryBuilder.range().onField(propertyValueExpr.getPropertyPath().asStringPath())) .below(value).createQuery(); case GREATER: return applyFieldBridge(false, propertyValueExpr.getPropertyPath(), queryBuilder.range().onField(propertyValueExpr.getPropertyPath().asStringPath())) .above(value).excludeLimit().createQuery(); case GREATER_OR_EQUAL: return applyFieldBridge(false, propertyValueExpr.getPropertyPath(), queryBuilder.range().onField(propertyValueExpr.getPropertyPath().asStringPath())) .above(value).createQuery(); default: throw new IllegalStateException("Unexpected comparison type: " + comparisonExpr.getComparisonType()); } }