private void assertIndexingWorksProperly(Object entity, Serializable id) { helper.add( entity ); helper.assertThat() .from( entity.getClass() ) .matchesExactlyIds( id ); }
@Test public void testNumericRangeQueries() { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); Query query = monthQb .range() .onField( "raindropInMm" ) .from( 0.23d ) .to( 0.24d ) .createQuery(); assertTrue( query.getClass().isAssignableFrom( NumericRangeQuery.class ) ); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 1 ); }
@Test public void testDslWithDate() throws Exception { Date nextEventDate = DateTools.round( NEXT_EVENT.getTime(), DateTools.Resolution.DAY ); Query query = queryBuilder().keyword().onField( "startDate" ).matching( nextEventDate ).createQuery(); helper.assertThat( query ).from( Fair.class ).matchesExactlyIds( LUCCA_ID ); }
@Test @TestForIssue(jiraKey = "HSEARCH-997") public void testByteDocumentIdExplicitlyMappedAsNumericField() { Query query = NumericFieldUtils.createNumericRangeQuery( "myId", (byte) 1, (byte) 1, true, true ); helper.assertThat( query ).from( PointOfInterest.class ) .matchesExactlyIds( (byte) 1 ); }
@Test @TestForIssue(jiraKey = "HSEARCH-1811") public void testWildcardQueryOnMultipleFields() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); Query query = monthQb .keyword() .wildcard() .onFields( "mythology", "history" ) .matching( "snowbo*" ) .createQuery(); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 2, 3 ); }
@Test public void testUseOfCustomFieldBridgeInstance() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); ConnectedTermMatchingContext termMatchingContext = (ConnectedTermMatchingContext) monthQb .keyword() .onField( MonthClassBridge.FIELD_NAME_1 ); Query query = termMatchingContext .withFieldBridge( new String2FieldBridgeAdaptor( new RomanNumberFieldBridge() ) ) .matching( 2 ) .createQuery(); helper.assertThat( query ).from( Month.class ).hasResultSize( 1 ); }
@Test @TestForIssue(jiraKey = "HSEARCH-3039") public void testSearchOnEmbeddedObjectId() { QueryBuilder qb = getCoffeeQueryBuilder(); Query query = qb.simpleQueryString() .onFields( "maker.id" ) .matching( "Stable" ) .createQuery(); helper.assertThat( query ).from( Coffee.class ) .matchesUnorderedIds( "Dharkan", "Arpeggio", "Decaffeinato" ); }
private AssertBuildingHSQueryContext assertProjection(Query query, String fieldName) { return helper.assertThat( query ) .from( SomeEntity.class ) .projecting( fieldName ); }
@Test // The custom field will use the default analyzer instead of the one defined on the field public void shouldNotBeAbleToFindAnalyzedCustomField() throws Exception { helper.assertThat( "copy_of_result", "HORRIBLE" ) .from( getEntityType() ) .matchesNone(); }
@Test public void shouldBeAbleToFindNotAnalyzedCustomField() throws Exception { helper.assertThat( "copy_of_subject", "CHELL" ) .from( getEntityType() ) .matchesExactlyIds( ENTITY_ID ); }
@Test public void shouldBeAbleToFindTheCustomIdField() throws Exception { helper.assertThat( "copy_of_id", "GLaDOS" ) .from( getEntityType() ) .matchesExactlyIds( ENTITY_ID ); }
private void assertThatFieldIsIndexed(String field, Object expectedValue, Sample sample) { helper.add( sample, sample.id ); Query query = queryBuilder().keyword().onField( field ).ignoreAnalyzer().matching( expectedValue ).createQuery(); helper.assertThat( query ) .from( Sample.class ) .projecting( field ) .matchesExactlySingleProjections( expectedValue ); }
@Test @TestForIssue( jiraKey = "HSEARCH-703" ) public void testPolymorphicQueryForUnindexedSuperTypeReturnsIndexedSubType() { final QueryBuilder builder = helper.queryBuilder( Object.class ); Query query = builder.all().createQuery(); helper.assertThat( query ).from( Object.class ) .as( "expected all instances of all indexed types" ) .hasResultSize( 8 ); }
@Test public void testPhraseQueryWithStopWords() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); Query query = monthQb .phrase() .onField( "mythology" ) .sentence( "colder and whitening" ) .createQuery(); helper.assertThat( query ).from( Month.class ).hasResultSize( 1 ); }
@Test @TestForIssue(jiraKey = "HSEARCH-2656") public void testNumericQueryWithFieldTypeOverriddenByFieldBridge() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); Query query = monthQb .keyword() .onField( "monthBase0" ) .ignoreFieldBridge().ignoreAnalyzer() .matching( 0 ) .createQuery(); helper.assertThat( query ).from( Month.class ).matchesUnorderedIds( 1 ); }
@Test @TestForIssue(jiraKey = "HSEARCH-2656") public void testNumericRangeQueryWithFieldTypeOverriddenByFieldBridge() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); Query query = monthQb .range() .onField( "monthBase0" ) .ignoreFieldBridge().ignoreAnalyzer() .below( 1 ).excludeLimit() .createQuery(); helper.assertThat( query ).from( Month.class ).matchesUnorderedIds( 1 ); }
@Test @TestForIssue(jiraKey = "HSEARCH-997") public void testByteDocumentIdMappedAsStringFieldByDefault() { Query query = TermRangeQuery.newStringRange( "id", "1", "1", true, true ); helper.assertThat( query ).from( Position.class ) .matchesExactlyIds( (byte) 1 ); }
@Test // The analyzer is applied for the annotated field public void shouldBeAbleToFindAnalyzedAnnotatedField() throws Exception { helper.assertThat( "result", "HORRIBLE" ) .from( getEntityType() ) .matchesExactlyIds( ENTITY_ID ); }
@Test public void testWildcardQuery() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); Query query = monthQb .keyword() .wildcard() .onField( "mythology" ) .matching( "mon*" ) .createQuery(); helper.assertThat( query ).from( Month.class ).hasResultSize( 3 ); }
@Test public void testUseOfFieldBridge() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); Query query = monthQb.keyword().onField( "monthValue" ).matching( 2 ).createQuery(); helper.assertThat( query ).from( Month.class ).hasResultSize( 1 ); }