@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 @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 filter_should() { QueryBuilder queryBuilder = helper.queryBuilder( IndexedEntity.class ); // A boolean predicate with filter + should clauses: // documents should match regardless of whether should clauses match. // Non-matching "should" clauses HSQuery query = helper.hsQuery( queryBuilder.bool() .must( queryBuilder.keyword().onField( "field1" ).matching( FIELD1_VALUE1 ).createQuery() ).disableScoring() .should( queryBuilder.keyword().onField( "field2" ).matching( FIELD2_VALUE2 ).createQuery() ) .should( queryBuilder.keyword().onField( "field3" ).matching( FIELD3_VALUE3 ).createQuery() ) .createQuery() ); helper.assertThat( query ) .matchesUnorderedIds( DOCUMENT_1 ); // One matching and one non-matching "should" clause query = helper.hsQuery( queryBuilder.bool() .must( queryBuilder.keyword().onField( "field1" ).matching( FIELD1_VALUE1 ).createQuery() ).disableScoring() .should( queryBuilder.keyword().onField( "field2" ).matching( FIELD2_VALUE1 ).createQuery() ) .should( queryBuilder.keyword().onField( "field3" ).matching( FIELD3_VALUE3 ).createQuery() ) .createQuery() ); helper.assertThat( query ) .matchesUnorderedIds( DOCUMENT_1 ); }