/** Built-in default programatic mapping for hibernate-search **/ private static SearchMapping getBuiltinMapping() { SearchMapping mapping = new SearchMapping(); // Map the getExternalId() method as a documentId for all domain classes // Note that hibernate-search currently requires this method to really exist in the // AbstractDomainObject class mapping.entity(AbstractDomainObject.class).property("externalId", ElementType.METHOD).documentId().name("id"); return mapping; }
private SearchMapping createSearchMapping() { SearchMapping mapping = new SearchMapping(); mapping.entity( ProgrammaticConfiguredValue.class ) .indexed() .property( "id", ElementType.FIELD ).documentId().name( "id" ) .property( "value", ElementType.FIELD ).field().store( Store.YES ).indexNullAs( "@null@" ); return mapping; }
@Test public void canSetIncludeEmbeddedObjectIdProgrammatically() throws Exception { try ( FullTextSessionBuilder builder = getFullTextSessionBuilder() ) { // given builder.fluentMapping() .entity( Address.class ) .indexed() .property( "addressId", ElementType.METHOD ) .documentId() .name( "id" ) .property( "country", ElementType.METHOD ) .indexEmbedded() .includeEmbeddedObjectId( true ); Long scotlandCountryId = setupTestData( builder ); FullTextSession s = builder.openFullTextSession(); // when QueryParser parser = new QueryParser( "id", TestConstants.standardAnalyzer ); org.apache.lucene.search.Query luceneQuery = parser.parse( "country.id:" + scotlandCountryId ); Transaction tx = s.beginTransaction(); // then FullTextQuery query = s.createFullTextQuery( luceneQuery ); assertEquals( 1, query.getResultSize() ); assertEquals( "Bob McRobb", ( (Address) query.list().iterator().next() ).getOwner() ); tx.commit(); s.close(); } }
@Test public void canSetIndexNullAsProgrammatically() throws Exception { try ( FullTextSessionBuilder builder = getFullTextSessionBuilder() ) { // given builder.fluentMapping() .entity( Address.class ) .indexed() .property( "addressId", ElementType.METHOD ) .documentId() .name( "id" ) .property( "country", ElementType.METHOD ) .indexEmbedded() .indexNullAs( IndexedEmbedded.DEFAULT_NULL_TOKEN ); setupTestData( builder ); FullTextSession s = builder.openFullTextSession(); // when QueryParser parser = new QueryParser( "id", TestConstants.standardAnalyzer ); org.apache.lucene.search.Query luceneQuery = parser.parse( "country:" + "_null_" ); Transaction tx = s.beginTransaction(); // then FullTextQuery query = s.createFullTextQuery( luceneQuery ); assertEquals( 1, query.getResultSize() ); assertEquals( "Alice Donellis", ( (Address) query.list().iterator().next() ).getOwner() ); tx.commit(); s.close(); } }
.property( "addressId", ElementType.METHOD ) .documentId() .name( "id" ) .property( "country", ElementType.METHOD ) .indexEmbedded()
.bridge(StringSetFieldBridge.class) .entity(NamedElementImpl.class) .property("name", ElementType.METHOD).field().name(ProcessDefinitionIndex.NAME) .entity(DescriptionElementImpl.class) // share with All DescriptionElement: processes, groups, ... .property("description", ElementType.METHOD).field().name(ProcessDefinitionIndex.DESCRIPTION) .entity(ProcessInstanceImpl.class) .property("commentFeed", ElementType.METHOD).indexEmbedded() .property("involvedUsers", ElementType.METHOD).field().name(ProcessInstanceIndex.INVOLVED_USER) .bridge(StringSetFieldBridge.class) .property("activities", ElementType.METHOD).indexEmbedded() .bridge(StringSetFieldBridge.class) .entity(LightProcessInstanceImpl.class) .property("nb", ElementType.FIELD).field().name(ProcessInstanceIndex.NB) .property("startedBy", ElementType.METHOD).field().name(ProcessInstanceIndex.STARTED_BY) .property("endedBy", ElementType.METHOD).field().name(ProcessInstanceIndex.ENDED_BY) .property("taskUser", ElementType.METHOD).field().name(ActivityInstanceIndex.USERID) .property("activityName", ElementType.METHOD).field().name(ActivityInstanceIndex.NAME) .property("state", ElementType.METHOD).field().name(ActivityInstanceIndex.STATE) .property("priority", ElementType.METHOD).field().name(ActivityInstanceIndex.PRIORITY) .index(Index.UN_TOKENIZED) .property("manager", ElementType.FIELD).field().name(UserIndex.MANAGER) .property("delegate", ElementType.FIELD).field().name(UserIndex.DELEGATE) .property("title", ElementType.FIELD).field().name(UserIndex.TITLE) .property("jobTitle", ElementType.FIELD).field().name(UserIndex.JOB_TITLE) .property("professionalContactInfo", ElementType.FIELD).indexEmbedded()
.classBridge( AddressClassBridge.class ) .analyzer( ENGLISH_ANALYZER_NAME ) .property( "addressId", ElementType.FIELD ).documentId().name( "id" ) .property( "lastUpdated", ElementType.FIELD ) .field().name( "last-updated" ) .entity( ProductCatalog.class ).indexed() .boost( 2 ) .property( "id", ElementType.FIELD ).documentId().name( "id" ) .property( "name", ElementType.FIELD ) .field().name( "productCatalogName" ).index( Index.YES ).analyzer( EN_ANALYZER_NAME ).store( Store.YES ) .indexed() .property( "libraryId", ElementType.FIELD ) .documentId().name( "id" ) .property( "name", ElementType.FIELD ) .dynamicBoost( CustomFieldBoostStrategy.class ) .indexed() .property( "deptsId", ElementType.FIELD ) .documentId().name( "id" ) .property( "branchHead", ElementType.FIELD ) .field().store( Store.YES )