valueMap.put("modelId", Arrays.asList(modelIds)); FullTextQuery query = getFullTextQuery(termination.createQuery()); if ("publishDate".equals(orderField)) { Sort sort = new Sort(new SortField("publishDate", SortField.Type.LONG, true));
valueMap.put("modelId", Arrays.asList(modelIds)); FullTextQuery query = getFullTextQuery(termination.createQuery()); if ("publishDate".equals(orderField)) { Sort sort = new Sort(new SortField("publishDate", SortField.Type.LONG, true));
FullTextQuery query = getFullTextQuery(termination.createQuery()); if ("publishDate".equals(orderField)) { Sort sort = new Sort(new SortField("publishDate", SortField.Type.LONG, true));
FullTextQuery query = getFullTextQuery(termination.createQuery()); if ("publishDate".equals(orderField)) { Sort sort = new Sort(new SortField("publishDate", SortField.Type.LONG, true));
@Override public List<?> searchEntriesForUserHelper(String userId, String field, String query, int startPosition, int maxResults) { if (userId == null || userId.isEmpty() || !idGenerator.isIdWellFormed(userId)) { return new ArrayList<Entry>(); } if (query == null) { return new ArrayList<Entry>(); } if (field == null) { return new ArrayList<Entry>(); } FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search .getFullTextEntityManager(getOrCreateEntityManager()); QueryBuilder qb = fullTextEntityManager.getSearchFactory() .buildQueryBuilder().forEntity(Entry.class).get(); org.apache.lucene.search.Query luceneQuery = qb .bool() .must(qb.keyword().onField(field).matching(query).createQuery()) .must(new TermQuery(new Term("userId", userId))).createQuery(); javax.persistence.Query jpaQuery = fullTextEntityManager .createFullTextQuery(luceneQuery, Entry.class) .setFirstResult(startPosition).setMaxResults(maxResults); return jpaQuery.getResultList(); }
@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 testBooleanQueriesMustNot() throws ParseException { loadTestingData(); Query query = Search.getSearchManager(cache).buildQueryBuilderForClass(Person.class).get().bool() .must(createQueryParser("name").parse("Goat")).not().createQuery(); CacheQuery<Person> cacheQuery = Search.getSearchManager(cache).getQuery(query); List<Person> found = cacheQuery.list(); assertEquals(1, found.size()); assert found.contains(person1); query = Search.getSearchManager(cache).buildQueryBuilderForClass(Person.class).get().bool() .must(createQueryParser("name").parse("Goat")).createQuery(); cacheQuery = Search.getSearchManager(cache).getQuery(query); found = cacheQuery.list(); assertEquals(2, found.size()); assert found.contains(person2); assert found.contains(person3); }
.createQuery() .createQuery(); hibQuery = fullTextSession.createFullTextQuery( query, POI.class ); hibQuery.setProjection( "id", "name" ); .createQuery() .createQuery(); org.apache.lucene.search.Query filteredQuery = new ConstantScoreQuery( SpatialQueryBuilderFromCoordinates.buildDistanceQuery(
@Test @TestForIssue(jiraKey = "HSEARCH-2565") public void testBooleanWithNullClauses() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); // must/should with null clauses Query query = monthQb .bool() .must( null ) .must( monthQb.keyword().onField( "mythology" ).matching( "colder" ).createQuery() ) .should( null ) .createQuery(); Assert.assertThat( query, CoreMatchers.instanceOf( BooleanQuery.class ) ); Assert.assertEquals( 1, ( (BooleanQuery) query ).clauses().size() ); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 1 ); // must not / filter with null clauses query = monthQb .bool() .must( null ).not() .must( null ).disableScoring() .must( monthQb.keyword().onField( "mythology" ).matching( "colder" ).createQuery() ) .createQuery(); Assert.assertThat( query, CoreMatchers.instanceOf( BooleanQuery.class ) ); Assert.assertEquals( 1, ( (BooleanQuery) query ).clauses().size() ); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 1 ); }
@Test public void must() { QueryBuilder queryBuilder = helper.queryBuilder( IndexedEntity.class ); HSQuery query = helper.hsQuery( queryBuilder.bool() .must( queryBuilder.keyword().onField( "field1" ).matching( FIELD1_VALUE1 ).createQuery() ) .createQuery() ); helper.assertThat( query ) .matchesUnorderedIds( DOCUMENT_1 ); query = helper.hsQuery( queryBuilder.bool() .must( queryBuilder.keyword().onField( "field1" ).matching( FIELD1_VALUE1 ).createQuery() ) .must( queryBuilder.keyword().onField( "field2" ).matching( FIELD2_VALUE2 ).createQuery() ) .createQuery() ); helper.assertThat( query ).matchesNone(); query = helper.hsQuery( queryBuilder.bool() .must( queryBuilder.keyword().onField( "field1" ).matching( FIELD1_VALUE1 ).createQuery() ) .must( queryBuilder.keyword().onField( "field2" ).matching( FIELD2_VALUE1 ).createQuery() ) .createQuery() ); helper.assertThat( query ) .matchesUnorderedIds( DOCUMENT_1 ); }
.bool() .must( monthQb.keyword().onField( "mythology" ).matching( "colder" ).createQuery() ) .createQuery();