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 testDslWithCalendar() throws Exception { Calendar year = createCalendar(); year.setTime( DateTools.round( FIRST_EDITION.getTime(), DateTools.Resolution.YEAR ) ); Query query = queryBuilder().keyword().onField( "since" ).matching( year ).createQuery(); helper.assertThat( query ).from( Fair.class ).matchesExactlyIds( LUCCA_ID ); }
@Test public void testFieldBridge() { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); Query query = monthQb.keyword() .onField( "monthRomanNumber" ) .matching( 2 ) .createQuery(); helper.assertThat( query ).from( Month.class ).matchesExactlyIds( 2 ); }
@Test public void testDslWithDefaultCalendarBridge() throws Exception { Query query = queryBuilder().keyword().onField( "announced" ).matching( ANNOUNCED ).createQuery(); helper.assertThat( query ).from( Fair.class ).matchesExactlyIds( LUCCA_ID ); }
@Test public void testDslWithDefaultDateBridge() throws Exception { Query query = queryBuilder().keyword().onField( "updated" ).matching( UPDATED ).createQuery(); helper.assertThat( query ).from( Fair.class ).matchesExactlyIds( LUCCA_ID ); }
@Test @TestForIssue(jiraKey = "HSEARCH-3039") public void testSearchOnDocumentId() { QueryBuilder qb = getCoffeeQueryBuilder(); Query query = qb.simpleQueryString() .onFields( "id" ) .matching( "Caramelito" ) .createQuery(); helper.assertThat( query ).from( Coffee.class ) .matchesExactlyIds( "Caramelito" ); }
private void assertSortedResults(Sort sort, int... expectedIds) { helper.assertThat() .from( Person.class ) .sort( sort ) .matchesExactlyIds( expectedIds ); }
@Test public void testSearchNumberWithFieldBridge() throws Exception { QueryBuilder qb = helper.queryBuilder( ContainerEntity.class ); Query q = qb.keyword().onField( "emb.num" ).matching( 7 ).createQuery(); assertQuery( q ).matchesExactlyIds( 1L ); }
@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-997") public void testShortDocumentIdExplicitlyMappedAsNumericField() { Query query = NumericFieldUtils.createNumericRangeQuery( "myId", (short) 1, (short) 1, true, true ); helper.assertThat( query ).from( Coordinate.class ) .matchesExactlyIds( (short) 1 ); }
@Test // The custom field used the default analyzer instead of the one defined on the field public void shouldBeAbleToFindAnalyzedCustomField() throws Exception { helper.assertThat( "copy_of_result", "horrible" ) .from( getEntityType() ) .matchesExactlyIds( ENTITY_ID ); }
@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 @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 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 public void testSearchString() throws Exception { QueryBuilder qb = helper.queryBuilder( ContainerEntity.class ); Query q = qb.keyword().onField( "emb.embeddedField" ).matching( "embedded" ).createQuery(); assertQuery( q ).matchesExactlyIds( 1L ); }
@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 ); }
@Test @TestForIssue( jiraKey = "HSEARCH-703" ) public void testPolymorphicQueryWithKeywordTermForUnindexedSuperTypeReturnsIndexedSubType() { final QueryBuilder builder = helper.queryBuilder( Car.class ); Query query = builder.keyword().onField( "name" ).matching( "Morris" ).createQuery(); helper.assertThat( query ).matchesExactlyIds( 2 ); }