private void prepareData() { TouristAttraction attraction = new TouristAttraction( 1, (short) 23, (short) 46L ); helper.add( attraction ); Score score1 = new Score(); score1.id = 1; score1.subscore = 100; helper.add( score1 ); ScoreBoard scoreboard = new ScoreBoard(); scoreboard.id = 1L; scoreboard.scores.add( score1 ); helper.add( scoreboard ); }
@Test public void testNumericFieldsTermQuery() { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); Query query = monthQb.keyword() .onField( "raindropInMm" ) .matching( 0.231d ) .createQuery(); assertTrue( query.getClass().isAssignableFrom( NumericRangeQuery.class ) ); helper.assertThat( query ).from( Month.class ).hasResultSize( 1 ); }
@Test public void testCustomAnalyzersAppliedForFieldsAddedInClassBridge() throws Exception { helper.index( new Foo( 1 ) ); String[] searchTokens = new String[] { "dog", "cat", "mouse" }; for ( int i = 0; i < searchTokens.length; i++ ) { TermQuery termQuery = new TermQuery( new Term( FooBridge.fieldNames[i], searchTokens[i] ) ); helper.assertThat( termQuery ) .as( "custom analyzer should have inserted search token" ) .matchesExactlyIds( 1 ); } }
public AssertBuildingHSQueryContext assertThat(String fieldName, String value) { return assertThat( termQuery( fieldName, value ) ); }
private void assertIndexingWorksProperly(Object entity, Serializable id) { helper.add( entity ); helper.assertThat() .from( entity.getClass() ) .matchesExactlyIds( id ); }
private void doDiscreteFacetingQuery() { QueryBuilder qb = helper.queryBuilder( FacetedEntity.class ); FacetingRequest request = qb.facet() .name( "myRequest" ) .onField( "stringField" ) .discrete() .includeZeroCounts( false ) .createFacetingRequest(); // Mainly, we're testing that executing the query with faceting enabled won't explode HSQuery hsQuery = helper.hsQuery( FacetedEntity.class ); hsQuery.getFacetManager().enableFaceting( request ); helper.assertThat( hsQuery ) .facets( "myRequest" ) .isEmpty(); }
private AssertBuildingHSQueryContext assertProjection(Query query, String fieldName) { return helper.assertThat( query ) .from( SomeEntity.class ) .projecting( fieldName ); }
public void index(Object entry, Serializable id) { index().push( entry, id ).execute(); }
private void initData() { helper.index( new IndexedEntity( DOCUMENT_1, helper.assertThat( helper.hsQuery( IndexedEntity.class ) ) .matchesUnorderedIds( DOCUMENT_1, DOCUMENT_2, DOCUMENT_3 );
@Test @TestForIssue(jiraKey = "HSEARCH-2420") public void testWithCustomId() throws Exception { String customId = "S:custom_id_325"; User user = new User(); user.setId( customId ); user.setSurname( "Lee" ); helper.executor( "tenant_id_with_underscores" ).add() .push( user, customId ) .execute(); helper.assertThat( "surname", "lee" ) .from( User.class ) .matchesExactlyIds( customId ); }
@Test public void testProvidedIdMapping() throws Exception { FullTextSession fullTextSession = Search.getFullTextSession( openSession() ); SearchIntegrator sf = fullTextSession.getSearchFactory().unwrap( SearchIntegrator.class ); ProvidedIdEntry person1 = new ProvidedIdEntry(); person1.setName( "Big Goat" ); person1.setBlurb( "Eats grass" ); ProvidedIdEntry person2 = new ProvidedIdEntry(); person2.setName( "Mini Goat" ); person2.setBlurb( "Eats cheese" ); ProvidedIdEntry person3 = new ProvidedIdEntry(); person3.setName( "Regular goat" ); person3.setBlurb( "Is anorexic" ); SearchITHelper helper = new SearchITHelper( () -> sf ); helper.index() .push( person1, 1 ) .push( person2, 2 ) .push( person3, 3 ) .execute(); Transaction transaction = fullTextSession.beginTransaction(); //we cannot use FTQuery because @ProvidedId does not provide the getter id and Hibernate Hsearch Query extension //needs it. So we use plain HSQuery helper.assertThat( "providedidentry.name", "goat" ) .from( ProvidedIdEntry.class ) .hasResultSize( 3 ); transaction.commit(); getSession().close(); }
@Test @TestForIssue( jiraKey = "HSEARCH-703" ) public void testObtainingBuilderForUnindexedTypeWithoutIndexedSubTypesCausesException() { try { helper.queryBuilder( Animal.class ); fail( "Obtaining a builder not allowed for unindexed type without any indexed sub-types." ); } catch (SearchException e) { // success } }
private HSQuery queryAll() { QueryBuilder qb = helper.queryBuilder( IndexedEntity.class ); return helper.hsQuery( IndexedEntity.class ) .sort( qb.sort().byField( "idSort" ).createSort() ); }
public EntityInstanceWorkContext index() { return executor().index(); }
private void deleteLog(long timestamp) { LogMessage log = new LogMessage(); log.timestamp = timestamp; helper.delete( LogMessage.class, log.timestamp ); }
public HSQuery hsQuery(Class<?> ... classes) { return hsQuery( new MatchAllDocsQuery(), classes ); }
@Test public void should() { QueryBuilder queryBuilder = helper.queryBuilder( IndexedEntity.class ); HSQuery query = helper.hsQuery( queryBuilder.bool() .should( queryBuilder.keyword().onField( "field1" ).matching( FIELD1_VALUE1 ).createQuery() ) .createQuery() ); helper.assertThat( query ) .matchesUnorderedIds( DOCUMENT_1 ); query = helper.hsQuery( queryBuilder.bool() .should( queryBuilder.keyword().onField( "field1" ).matching( FIELD1_VALUE1 ).createQuery() ) .should( queryBuilder.keyword().onField( "field1" ).matching( FIELD1_VALUE2 ).createQuery() ) .createQuery() ); helper.assertThat( query ) .matchesUnorderedIds( DOCUMENT_1, DOCUMENT_2 ); }
@Test public void testIndexingWithNullEncodingFieldBridge() { Sample entity = new Sample(); entity.id = 1; entity.description = "null date"; entity.deletionDate = null; // should trigger the marker token helper.add( entity ); Query termQuery = NumericFieldUtils.createExactMatchQuery( "deletionDate", Long.parseLong( "-1" ) ); helper.assertThat( termQuery ) .from( Sample.class ) .hasResultSize( 1 ); }
@Test public void clear_maxResult() throws Exception { HSQuery hsQuery = queryAll(); helper.assertThat( hsQuery ).matchesExactlyIds( 0, 1, 2 ); hsQuery.maxResults( 2 ); helper.assertThat( hsQuery ).matchesExactlyIds( 0, 1 ); hsQuery.maxResults( 1 ); helper.assertThat( hsQuery ).matchesExactlyIds( 0 ); }
public void index(Iterable<?> entries) { index().push( entries ).execute(); }