@Override public void defineMappings(Cache cache, SearchMapping searchMapping) { searchMapping.entity(GenericData.Record.class) .indexed() .classBridgeInstance(new ValueWrapperFieldBridge()) .norms(Norms.NO) .analyze(Analyze.NO) .store(Store.NO); } }
@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() ) ); }
@Factory public SearchMapping build() { SearchMapping mapping = new SearchMapping(); mapping .analyzerDef( "ngram", StandardTokenizerFactory.class ) .filter( LowerCaseFilterFactory.class ) .filter( StopFilterFactory.class ) .param( "words", "non-existent-resourcename.file" ) // We must mark at least one entity as indexed, otherwise analyzer definitions are not initialized (no need to) .entity( SomeHibernateEntity.class ).indexed(); return mapping; }
@Test public void testTypeWithNoDocumentIdThrowsException() { SearchConfigurationForTest cfg = getManualConfiguration(); SearchMapping mapping = new SearchMapping(); mapping .entity( Foo.class ).indexed() ; cfg.setProgrammaticMapping( mapping ); try { integratorResource.create( cfg ); fail( "Invalid configuration should have thrown an exception" ); } catch (SearchException e) { assertTrue( e.getMessage().startsWith( "HSEARCH000177" ) ); } }
@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; }
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 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 usingDefaultSettings() { SearchMapping mapping = new SearchMapping(); mapping .entity( Book.class ).indexed() .providedId().name( "myID" ) //Entity missing both @DocumentId and @ProvidedId: .property( "title", ElementType.FIELD ).field() .property( "text", ElementType.FIELD ).field() ; SearchConfigurationForTest cfg = new SearchConfigurationForTest() .setProgrammaticMapping( mapping ) //.setIdProvidedImplicit( false ) //Test it's the default .addClass( Book.class ); storeBooksViaProvidedId( cfg, "myID", false ); }
@Test public void usingProvidedIdAsOptionsOverride() { SearchMapping mapping = new SearchMapping(); mapping .entity( Book.class ).indexed() .providedId().name( "myID" ) //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, "myID", 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() ); }
@Test public void usingExplicitProvidedId() { SearchMapping mapping = new SearchMapping(); mapping .entity( Book.class ).indexed() .providedId().name( "myID" ) //Entity missing both @DocumentId and @ProvidedId: .property( "title", ElementType.FIELD ).field() .property( "text", ElementType.FIELD ).field() ; SearchConfigurationForTest cfg = new SearchConfigurationForTest() .setProgrammaticMapping( mapping ) .setIdProvidedImplicit( false ) //DEFAULT .addClass( Book.class ); storeBooksViaProvidedId( cfg, "myID", false ); }
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" ) ); }