Integer pageSize) { QueryBuilder queryBuilder = getFullTextQueryBuilder(); MustJunction termination = queryBuilder.bool() .must(queryBuilder.keyword().onFields(CommonUtils.empty(tagIds) ? textFields : tagFields) .matching(CommonUtils.empty(tagIds) ? text : tagIds).createQuery()) BooleanJunction<BooleanJunction> tempJunction = queryBuilder.bool(); for (Integer categoryId : categoryIds) { tempJunction.should(new TermQuery(new Term("categoryId", categoryId.toString()))); BooleanJunction<BooleanJunction> tempJunction = queryBuilder.bool(); for (String modelId : modelIds) { tempJunction.should(new TermQuery(new Term("modelId", modelId)));
Integer pageSize) { QueryBuilder queryBuilder = getFullTextQueryBuilder(); MustJunction termination = queryBuilder.bool() .must(queryBuilder.keyword().onFields(CommonUtils.empty(tagIds) ? textFields : tagFields) .matching(CommonUtils.empty(tagIds) ? text : tagIds).createQuery()) BooleanJunction<BooleanJunction> tempJunction = queryBuilder.bool(); for (Integer categoryId : categoryIds) { tempJunction.should(new TermQuery(new Term("categoryId", categoryId.toString()))); BooleanJunction<BooleanJunction> tempJunction = queryBuilder.bool(); for (String modelId : modelIds) { tempJunction.should(new TermQuery(new Term("modelId", modelId)));
Date startPublishDate, Date endPublishDate, String orderField, Integer pageIndex, Integer pageSize) { QueryBuilder queryBuilder = getFullTextQueryBuilder(); MustJunction termination = queryBuilder.bool() .must(queryBuilder.keyword().onFields(CommonUtils.empty(tagId) ? textFields : tagFields) .matching(CommonUtils.empty(tagId) ? text : tagId).createQuery())
Date startPublishDate, Date endPublishDate, String orderField, Integer pageIndex, Integer pageSize) { QueryBuilder queryBuilder = getFullTextQueryBuilder(); MustJunction termination = queryBuilder.bool() .must(queryBuilder.keyword().onFields(CommonUtils.empty(tagId) ? textFields : tagFields) .matching(CommonUtils.empty(tagId) ? text : tagId).createQuery())
.sentence(theText.toLowerCase()).createQuery(); Query query = qb.bool()
FullTextEntityManager em = org.hibernate.search.jpa.Search.getFullTextEntityManager(myEntityManager); QueryBuilder qb = em.getSearchFactory().buildQueryBuilder().forEntity(TermConcept.class).get(); BooleanJunction<?> bool = qb.bool();
BooleanJunction<?> bool = qb.bool();
//look for users whos id is 1 and createDate is more than lastMonth Date lastMonth = ...; QueryBuilder userQB = searchFactory.buildQueryBuilder().forEntity( User.class ).get(); Query luceneQuery = userQB .bool() .must( userQB.keyword().onField("id").matching("1").createQuery() ) .must( userQB.range().onField("creationDate").above(lastMonth) .createQuery() ) .createQuery();
@Override public Query getQuery() { BooleanJunction<BooleanJunction> booleanJunction = builder.bool(); for ( Predicate<Query> predicate : children ) { booleanJunction.should( predicate.getQuery() ); } return booleanJunction.createQuery(); } }
@Override public Query visit(OrExpr orExpr) { BooleanJunction<BooleanJunction> booleanJunction = queryBuilder.bool(); for (BooleanExpr c : orExpr.getChildren()) { Query transformedChild = c.acceptVisitor(this); booleanJunction.should(transformedChild); } return booleanJunction.createQuery(); }
@Override public Query visit(OrExpr orExpr) { BooleanJunction<BooleanJunction> booleanJunction = queryBuilder.bool(); for (BooleanExpr c : orExpr.getChildren()) { Query transformedChild = c.acceptVisitor(this); booleanJunction.should(transformedChild); } return booleanJunction.createQuery(); }
@Override public Query visit(NotExpr notExpr) { Query transformedChild = notExpr.getChild().acceptVisitor(this); return queryBuilder.bool().must(transformedChild).not().createQuery(); }
@SuppressWarnings({ "rawtypes" }) private FullTextQuery createFullTextQueryForfindExactByAttribute(Map<String, String> eqSentenceOnField) { FullTextSession fullTextSession = getFullTextSession(); QueryBuilder qb = getQueryBuilder(fullTextSession); BooleanJunction<BooleanJunction> combinedQuery = qb.bool(); combinedQuery = addMustPhraseWithAttributesOnFields(eqSentenceOnField, qb, combinedQuery); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(combinedQuery.createQuery()); return fullTextQuery; }
@SuppressWarnings({ "rawtypes" }) private FullTextQuery createFullTextQueryForfindNotExactByAttributeWKeywords(Map<String, String> eqSentenceOnField) { FullTextSession fullTextSession = getFullTextSession(); QueryBuilder qb = getQueryBuilder(fullTextSession); BooleanJunction<BooleanJunction> combinedQuery = qb.bool(); combinedQuery = addShouldKeywordsWithAttributesOnFields(eqSentenceOnField, qb, combinedQuery); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(combinedQuery.createQuery()); return fullTextQuery; }
@Override public Query visit(NotExpr notExpr) { Query transformedChild = notExpr.getChild().acceptVisitor(this); return queryBuilder.bool().must(transformedChild).not().createQuery(); }
@SuppressWarnings({ "rawtypes" }) private FullTextQuery createFullTextQueryForfindMixedByAttributeWKeywords(Map<String, String> eqSentenceOnField, Map<String, String> eqMustSentenceOnField) { FullTextSession fullTextSession = getFullTextSession(); QueryBuilder qb = getQueryBuilder(fullTextSession); BooleanJunction<BooleanJunction> combinedQuery = qb.bool(); combinedQuery = addShouldWMustKeywordsWithAttributesOnFields(eqSentenceOnField,eqMustSentenceOnField, qb, combinedQuery); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(combinedQuery.createQuery()); return fullTextQuery; }
@SuppressWarnings("rawtypes") private FullTextQuery createFullTextQueryForfindStartingUsingWildcardAndExactByAttributes(Map<String, String> startSentenceOnField, Map<String, String> eqSentenceOnField) { FullTextSession fullTextSession = getFullTextSession(); QueryBuilder qb = getQueryBuilder(fullTextSession); BooleanJunction<BooleanJunction> combinedQuery = qb.bool(); combinedQuery = addMustPhraseWithAttributesOnFields(eqSentenceOnField, qb, combinedQuery); combinedQuery = addMustWildcardWithStartingAttributesOnFields(startSentenceOnField, qb, combinedQuery); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(combinedQuery.createQuery()); return fullTextQuery; }
@SuppressWarnings("rawtypes") private FullTextQuery createFullTextQueryForfindMultiFieldSameAttributesAndExactByAttributes(Map<String, Set<String>> attributeForMultipleFieldsMap, Map<String, String> eqSentenceOnField) { FullTextSession fullTextSession = getFullTextSession(); QueryBuilder qb = getQueryBuilder(fullTextSession); BooleanJunction<BooleanJunction> combinedQuery = qb.bool(); combinedQuery = addMustPhraseWithAttributesOnFields(eqSentenceOnField, qb, combinedQuery); combinedQuery = addMustPhraseWithMultiFieldOnAttribute(attributeForMultipleFieldsMap, qb, combinedQuery); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(combinedQuery.createQuery()); return fullTextQuery; }
@Test public void minimumShouldMatch_error_multipleConflictingConstraints() { QueryBuilder queryBuilder = helper.queryBuilder( IndexedEntity.class ); thrown.expect( SearchException.class ); thrown.expectMessage( "Multiple conflicting minimumShouldMatch constraints" ); queryBuilder.bool().minimumShouldMatchNumber( -1 ).minimumShouldMatchPercent( 100 ); }
@Test(expected = SearchException.class) public void testIllegalBooleanJunction() { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); //forgetting to set any condition on the boolean, an exception shall be thrown: BooleanJunction<?> booleanJunction = monthQb.bool(); assertTrue( booleanJunction.isEmpty() ); booleanJunction.createQuery(); Assert.fail( "should not reach this point" ); }