@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() ) ); }
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; }
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 ); }
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; }
@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 ); }
@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(); } }
@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(); } }
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() ); }
.documentId() .name( "id" ) .property( "country", ElementType.METHOD ) .indexEmbedded() .includePaths( "id", "name" )
private void verifyIndexManagerTypeIs(Class<? extends IndexManager> expectedIndexManagerClass, SearchConfigurationForTest cfg) { SearchMapping mapping = new SearchMapping(); mapping .entity( Document.class ).indexed().indexName( "documents" ) .property( "id", ElementType.FIELD ).documentId() .property( "title", ElementType.FIELD ).field(); cfg.setProgrammaticMapping( mapping ); cfg.addClass( Document.class ); SearchIntegrator sf = integratorResource.create( cfg ); Assert.assertEquals( expectedIndexManagerClass, extractDocumentIndexManagerClassName( sf, "documents" ) ); // trigger a SearchFactory rebuild: sf.addClasses( Dvd.class ); // and verify the option is not lost: Assert.assertEquals( expectedIndexManagerClass, extractDocumentIndexManagerClassName( sf, "dvds" ) ); Assert.assertEquals( expectedIndexManagerClass, extractDocumentIndexManagerClassName( sf, "documents" ) ); }
.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("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) .entity(LightActivityInstanceImpl.class) .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)
.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 ) .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( "libraryId", ElementType.FIELD ) .documentId().name( "id" ) .property( "name", ElementType.FIELD ) .dynamicBoost( CustomFieldBoostStrategy.class ) .field().store( Store.YES ) .property( "deptsId", ElementType.FIELD ) .documentId().name( "id" ) .property( "branchHead", ElementType.FIELD ) .field().store( Store.YES ) .property( "network", ElementType.FIELD )