@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 ); }
@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 ); }
@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() ) ); }
final SearchMapping mapping = new SearchMapping(); mapping.entity(BondPVO.class).indexed() .property("id", ElementType.METHOD).field() .property("name", ElementType.METHOD).field() .property("isin", ElementType.METHOD).field();
@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() ); }
@Test public void testGetIndexedTypeSingleIndexedType() { SearchConfigurationForTest cfg = getManualConfiguration(); SearchMapping mapping = new SearchMapping(); mapping .entity( Foo.class ).indexed() .property( "id", FIELD ).documentId() ; cfg.setProgrammaticMapping( mapping ); SearchIntegrator si = integratorResource.create( cfg ); IndexedTypeSet indexedClasses = si.getIndexedTypeIdentifiers(); assertEquals( "Wrong number of indexed entities", 1, indexedClasses.size() ); assertTrue( indexedClasses.iterator().next().equals( new PojoIndexedTypeIdentifier( Foo.class ) ) ); }
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; }
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; }
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 ); }
@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 ); }
@Factory public SearchMapping create() { SearchMapping searchMapping = new SearchMapping(); searchMapping.analyzerDef( "english", StandardTokenizerFactory.class ) .filter( LowerCaseFilterFactory.class ) .filter( SnowballPorterFilterFactory.class ) .analyzerDef( "english", StandardTokenizerFactory.class ) // ups duplicate name here - this should throw an exception .filter( LowerCaseFilterFactory.class ) .filter( GermanStemFilterFactory.class ) .entity( BlogEntry.class ) .indexed() .property( "title", ElementType.METHOD ); return searchMapping; } }
@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 usingConfigurationTypeOverride() { SearchMapping mapping = new SearchMapping(); mapping .entity( Book.class ).indexed() //Entity missing both @DocumentId and @ProvidedId: .property( "title", ElementType.FIELD ).field() .property( "text", ElementType.FIELD ).field() ; SearchConfigurationForTest cfg = new SearchConfigurationForTest() .setProgrammaticMapping( mapping ) .setIdProvidedImplicit( true ) .addClass( Book.class ); storeBooksViaProvidedId( cfg, ProvidedId.defaultFieldName, false ); }
@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(); } }
@Test public void testGetTypeDescriptorForIndexedType() { SearchConfigurationForTest cfg = getManualConfiguration(); SearchMapping mapping = new SearchMapping(); mapping .entity( Foo.class ).indexed() .property( "id", FIELD ).documentId() ; cfg.setProgrammaticMapping( mapping ); SearchIntegrator si = integratorResource.create( cfg ); IndexedTypeDescriptor indexedTypeDescriptor = si.getIndexedTypeDescriptor( new PojoIndexedTypeIdentifier( Foo.class ) ); assertNotNull( indexedTypeDescriptor ); assertTrue( indexedTypeDescriptor.isIndexed() ); }
@Test public void exceptionThrownWhenNotEnabled() { SearchMapping mapping = new SearchMapping(); mapping .entity( Book.class ).indexed() //Entity missing both @DocumentId and @ProvidedId: .property( "title", ElementType.FIELD ).field() .property( "text", ElementType.FIELD ).field() ; SearchConfigurationForTest cfg = new SearchConfigurationForTest() .setProgrammaticMapping( mapping ) .addClass( Book.class ); exceptions.expect( SearchException.class ); exceptions.expectMessage( "HSEARCH000177" ); storeBooksViaProvidedId( cfg, ProvidedId.defaultFieldName, false ); }
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() ); }
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" ) ); }
private FullTextSessionBuilder configure(boolean withClassBridgeOnItem, int depth, boolean withClassBridgeOnCatalog) { FullTextSessionBuilder builder = new FullTextSessionBuilder() .addAnnotatedClass( Catalog.class ) .addAnnotatedClass( CatalogItem.class ) .addAnnotatedClass( Consumer.class ) .addAnnotatedClass( Item.class ); SearchMapping fluentMapping = builder.fluentMapping(); // mapping for Catalog EntityMapping catalogMapping = fluentMapping .entity( Catalog.class ); if ( withClassBridgeOnCatalog ) { catalogMapping.classBridge( NoopClassBridge.class ); } catalogMapping .property( "catalogItems", ElementType.FIELD ).containedIn(); // mapping for CatalogItem fluentMapping.entity( CatalogItem.class ) .property( "item", ElementType.FIELD ).containedIn() .property( "catalog", ElementType.FIELD ).indexEmbedded(); // mapping for Item IndexedMapping itemMapping = fluentMapping .entity( Item.class ) .indexed(); if ( withClassBridgeOnItem ) { itemMapping.classBridge( NoopClassBridge.class ); } itemMapping.property( "catalogItems", ElementType.FIELD ).indexEmbedded().depth( depth ); return builder.build(); }