public DocumentIdMapping documentId() { return new DocumentIdMapping( property, entity, mapping ); }
public AnalyzerDefMapping analyzerDef(String name, Class<? extends TokenizerFactory> tokenizerFactory) { return analyzerDef( name, "", tokenizerFactory ); }
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; }
.property("uuid", ElementType.FIELD).field().name(ProcessDefinitionIndex.UUID) .bridge(UUIDFieldBridge.class) .property("categoryNames", ElementType.METHOD).field().name(ProcessDefinitionIndex.CATEGORY_NAME) .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) .property("dbid", ElementType.FIELD).documentId().name(ProcessInstanceIndex.DBID) .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() .property("lastKnownVariableValues", ElementType.METHOD).field().name("variable") .bridge(ObjectMapFieldBridge.class) .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) .entity(Comment.class) .property("message", ElementType.METHOD).field().name(CommentIndex.MESSAGE) .property("userId", ElementType.METHOD).field().name(CommentIndex.AUTHOR) .entity(TaskInstance.class)
@SuppressWarnings("unchecked") private void verifyOptimizerImplementationIs(Class type, SearchConfigurationForTest cfg) { SearchMapping mapping = new SearchMapping(); mapping .entity( Document.class ).indexed() .property( "id", ElementType.FIELD ).documentId() .property( "title", ElementType.FIELD ).field() ; cfg.setProgrammaticMapping( mapping ); cfg.addClass( Document.class ); SearchIntegrator sf = integratorResource.create( cfg ); EntityIndexBinding indexBindingForEntity = sf.getIndexBindings().get( Document.class ); DirectoryBasedIndexManager indexManager = (DirectoryBasedIndexManager) indexBindingForEntity.getIndexManagerSelector().all().iterator().next(); OptimizerStrategy optimizerStrategy = indexManager.getOptimizerStrategy(); Assert.assertTrue( type.isAssignableFrom( optimizerStrategy.getClass() ) ); }
.classBridge( AddressClassBridge.class ) .analyzer( ENGLISH_ANALYZER_NAME ) .property( "addressId", ElementType.FIELD ).documentId().name( "id" ) .property( "lastUpdated", ElementType.FIELD ) .field().name( "last-updated" ) .analyzer( EN_ANALYZER_NAME ).store( Store.YES ) .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 ) .property( "items", ElementType.FIELD ) .property( "id", ElementType.FIELD ) .documentId() .sortableField() .property( "description", ElementType.FIELD ) .field().name( "description" ).analyzer( EN_ANALYZER_NAME ).index( Index.YES ).store( Store.YES ) .indexed() .property( "libraryId", ElementType.FIELD ) .documentId().name( "id" ) .property( "name", ElementType.FIELD ) .dynamicBoost( CustomFieldBoostStrategy.class ) .field().store( Store.YES ) .indexed() .property( "deptsId", ElementType.FIELD )
/** 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; }
@Test public void testGetIndexedTypesMultipleTypes() { SearchConfigurationForTest cfg = getManualConfiguration(); SearchMapping mapping = new SearchMapping(); mapping .entity( Foo.class ).indexed() .property( "id", FIELD ).documentId() .entity( Bar.class ).indexed() .property( "id", FIELD ).documentId() ; cfg.setProgrammaticMapping( mapping ); SearchIntegrator si = integratorResource.create( cfg ); IndexedTypeSet indexedClasses = si.getIndexedTypeIdentifiers(); assertEquals( "Wrong number of indexed entities", 2, indexedClasses.size() ); }
@Override public void configure(Map<String,Object> cfg) { SearchMapping mapping = new SearchMapping(); mapping .entity( PlainPerson.class ) .indexed() .property( "id", ElementType.FIELD ) .documentId() .bridge( PersonPKMetadataProviderBridge.class ) .property( "", ElementType.FIELD ) .field(); cfg.put( Environment.MODEL_MAPPING, 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(); } }
static SearchMapping buildMappingDefinition() { SearchMapping mapping = new SearchMapping(); mapping .entity( TelephoneRecord.class ) .indexed() .indexName( "phoneNumbersIndex" ) .property( "id", ElementType.FIELD ).documentId() .property( "phone", ElementType.FIELD ).field().analyze( Analyze.NO ).store( Store.YES ) .entity( AddressBook.class ) .indexed() .indexName( "addressBookIndex" ) .property( "id", ElementType.FIELD ).documentId() .property( "name", ElementType.FIELD ).field().store( Store.YES ) ; return mapping; }
@Override public void configure(Map<String,Object> cfg) { SearchMapping mapping = new SearchMapping(); mapping .entity( PlainPerson.class ) .indexed() .property( "id", ElementType.FIELD ) .documentId() .bridge( PersonPKBridge.class ) .property( "", ElementType.FIELD ) .field(); cfg.put( Environment.MODEL_MAPPING, mapping ); }
@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(); } }
protected MutableSearchFactory getMutableSearchFactoryWithSingleEntity(SearchConfigurationForTest cfg) { SearchMapping mapping = new SearchMapping(); mapping .entity( Document.class ).indexed().indexName( "index1" ) .property( "id", ElementType.FIELD ).documentId() .property( "title", ElementType.FIELD ).field() ; cfg.setProgrammaticMapping( mapping ); cfg.addClass( Document.class ); return (MutableSearchFactory) integratorResource.create( cfg ); }
public DocumentIdMapping documentId() { return new DocumentIdMapping( property, entity, mapping ); }
public AnalyzerDefMapping analyzerDef(String name, Class<? extends TokenizerFactory> tokenizerFactory) { return analyzerDef( name, "", tokenizerFactory ); }
@Before public void setUp() { manualConfiguration = new SearchConfigurationForTest(); SearchMapping searchMapping = new SearchMapping(); searchMapping.entity( Document.class ).indexed() .property( "id", ElementType.FIELD ).documentId() .property( "title", ElementType.FIELD ).field(); manualConfiguration.setProgrammaticMapping( searchMapping ); manualConfiguration.addClass( Document.class ); }
@Test public void documentIdNotOverriden() { SearchMapping mapping = new SearchMapping(); mapping .entity( Book.class ).indexed() .property( "title", ElementType.FIELD ).documentId() .property( "text", ElementType.FIELD ).field() ; SearchConfigurationForTest cfg = new SearchConfigurationForTest() .setProgrammaticMapping( mapping ) //.setIdProvidedImplicit( false ) //Test it's the default .addClass( Book.class ); storeBooksViaProvidedId( cfg, "title", true ); }
private void verifyTransactionsExpectedOption(boolean expectation, SearchConfigurationForTest cfg) { SearchMapping mapping = new SearchMapping(); mapping .entity( Document.class ).indexed() .property( "id", ElementType.FIELD ).documentId() .property( "title", ElementType.FIELD ).field() ; cfg.setProgrammaticMapping( mapping ); cfg.addClass( Document.class ); MutableSearchFactory sf = (MutableSearchFactory) integratorResource.create( cfg ); Assert.assertEquals( expectation, sf.isTransactionManagerExpected() ); // trigger a SearchFactory rebuild: sf.addClasses( Dvd.class ); // and verify the option is not lost: Assert.assertEquals( expectation, sf.isTransactionManagerExpected() ); }