private void addDisplayFilterExact(QueryBuilder qb, BooleanJunction<?> bool, ValueSet.ConceptSetFilterComponent nextFilter) { bool.must(qb.phrase().onField("myDisplay").sentence(nextFilter.getValue()).createQuery()); }
private void addDisplayFilterInexact(QueryBuilder qb, BooleanJunction<?> bool, ValueSet.ConceptSetFilterComponent nextFilter) { Query textQuery = qb .phrase() .withSlop(2) .onField("myDisplay").boostedTo(4.0f) .andField("myDisplayEdgeNGram").boostedTo(2.0f) // .andField("myDisplayNGram").boostedTo(1.0f) // .andField("myDisplayPhonetic").boostedTo(0.5f) .sentence(nextFilter.getValue().toLowerCase()).createQuery(); bool.must(textQuery); }
QueryBuilder queryBuilder = getFullTextQueryBuilder(); MustJunction termination = queryBuilder.bool() .must(queryBuilder.keyword().onFields(CommonUtils.empty(tagId) ? textFields : tagFields) .matching(CommonUtils.empty(tagId) ? text : tagId).createQuery()) .must(new TermQuery(new Term("siteId", siteId.toString())));
QueryBuilder queryBuilder = getFullTextQueryBuilder(); MustJunction termination = queryBuilder.bool() .must(queryBuilder.keyword().onFields(CommonUtils.empty(tagId) ? textFields : tagFields) .matching(CommonUtils.empty(tagId) ? text : tagId).createQuery()) .must(new TermQuery(new Term("siteId", siteId.toString())));
.must(qb.keyword().onField("myResourceLinksField").matching(pid.toString()).createQuery()) .must(textQuery) .createQuery();
QueryBuilder queryBuilder = getFullTextQueryBuilder(); MustJunction termination = queryBuilder.bool() .must(queryBuilder.keyword().onFields(CommonUtils.empty(tagIds) ? textFields : tagFields) .matching(CommonUtils.empty(tagIds) ? text : tagIds).createQuery()) .must(new TermQuery(new Term("siteId", siteId.toString())));
BooleanJunction<?> bool = qb.bool(); bool.must(qb.keyword().onField("myCodeSystemVersionPid").matching(csv.getPid()).createQuery()); bool.must(qb.keyword().onField("myParentPids").matching("" + code.getId()).createQuery()); } else { throw new InvalidRequestException("Don't know how to handle op=" + nextFilter.getOp() + " on property " + nextFilter.getProperty()); bool.must(query); bool.must(new TermsQuery(term));
QueryBuilder queryBuilder = getFullTextQueryBuilder(); MustJunction termination = queryBuilder.bool() .must(queryBuilder.keyword().onFields(CommonUtils.empty(tagIds) ? textFields : tagFields) .matching(CommonUtils.empty(tagIds) ? text : tagIds).createQuery()) .must(new TermQuery(new Term("siteId", siteId.toString())));
@SuppressWarnings("rawtypes") private BooleanJunction<BooleanJunction> addMustPhraseWithAttributesOnFields(Map<String, String> eqSentenceOnField, QueryBuilder qb, BooleanJunction<BooleanJunction> combinedQuery) { for(String field : eqSentenceOnField.keySet()){ String value = eqSentenceOnField.get(field); Query luceneQuery = qb.phrase() .onField(field) .sentence(value) .createQuery(); combinedQuery.must(luceneQuery); } return combinedQuery; }
@Override public Query visit(NotExpr notExpr) { Query transformedChild = notExpr.getChild().acceptVisitor(this); return queryBuilder.bool().must(transformedChild).not().createQuery(); }
@Override public Query visit(NotExpr notExpr) { Query transformedChild = notExpr.getChild().acceptVisitor(this); return queryBuilder.bool().must(transformedChild).not().createQuery(); }
private void addDisplayFilterExact(QueryBuilder qb, BooleanJunction<?> bool, ValueSet.ConceptSetFilterComponent nextFilter) { bool.must(qb.phrase().onField("myDisplay").sentence(nextFilter.getValue()).createQuery()); }
@Override public Query getQuery() { return builder.bool().must( getChild().getQuery() ).not().createQuery(); }
@Override public Query visit(ConstantBooleanExpr constantBooleanExpr) { Query all = queryBuilder.all().createQuery(); return constantBooleanExpr.getValue() ? all : queryBuilder.bool().must(all).not().createQuery(); }
@Override public Query visit(ConstantBooleanExpr constantBooleanExpr) { Query all = queryBuilder.all().createQuery(); return constantBooleanExpr.getValue() ? all : queryBuilder.bool().must(all).not().createQuery(); }
private void addDisplayFilterInexact(QueryBuilder qb, BooleanJunction<?> bool, ValueSet.ConceptSetFilterComponent nextFilter) { Query textQuery = qb .phrase() .withSlop(2) .onField("myDisplay").boostedTo(4.0f) .andField("myDisplayEdgeNGram").boostedTo(2.0f) // .andField("myDisplayNGram").boostedTo(1.0f) // .andField("myDisplayPhonetic").boostedTo(0.5f) .sentence(nextFilter.getValue().toLowerCase()).createQuery(); bool.must(textQuery); }
@Test @TestForIssue(jiraKey = "HSEARCH-2034") public void testBooleanWithoutScoring() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); //must + disable scoring Query query = monthQb .bool() .must( monthQb.keyword().onField( "mythology" ).matching( "colder" ).createQuery() ) .disableScoring() .createQuery(); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 1 ); assertTrue( query instanceof BooleanQuery ); BooleanQuery bq = (BooleanQuery) query; BooleanClause firstBooleanClause = bq.clauses().get( 0 ); assertFalse( firstBooleanClause.isScoring() ); }
@Test public void should_mustNot() { QueryBuilder queryBuilder = helper.queryBuilder( IndexedEntity.class ); HSQuery query = helper.hsQuery( queryBuilder.bool() .should( queryBuilder.keyword().onField( "field1" ).matching( FIELD1_VALUE1 ).createQuery() ) .should( queryBuilder.keyword().onField( "field1" ).matching( FIELD1_VALUE3 ).createQuery() ) .must( queryBuilder.keyword().onField( "field1" ).matching( FIELD1_VALUE1 ).createQuery() ).not() .createQuery() ); helper.assertThat( query ) .matchesUnorderedIds( DOCUMENT_3 ); }