private DocumentBuilderIndexedEntity extractDocumentBuilder(Document document) throws IOException { //maybe we can avoid document extraction: if ( singleEntityBindingIfPossible != null ) { return singleEntityBindingIfPossible.getDocumentBuilder(); } String className = document.get( ProjectionConstants.OBJECT_CLASS ); //and quite likely we can avoid the Reflect helper: EntityIndexBinding entityBinding = targetedEntityBindings.get( className ); if ( entityBinding != null ) { return entityBinding.getDocumentBuilder(); } return DocumentBuilderHelper.getDocumentBuilder( className, extendedIntegrator ); }
private void performShardAwareOperation(IndexedTypeSet entityTypes, BiConsumer<IndexManager, IndexedTypeIdentifier> operation) { for (IndexedTypeIdentifier type : entityTypes) { EntityIndexBinding indexBindingForEntity = integrator.getIndexBinding(type); if (indexBindingForEntity != null) { Set<IndexManager> indexManagers = indexBindingForEntity.getIndexManagerSelector().forExisting(type, null, null); indexManagers.forEach(im -> operation.accept(im, type)); } } } }
private EntityIndexingInterceptor getEntityInterceptor() { EntityIndexBinding indexBindingForEntity = extendedIntegrator.getIndexBinding( this.typeIdentifier ); return indexBindingForEntity != null ? indexBindingForEntity.getEntityIndexingInterceptor() : null; }
EntityIndexingInterceptor interceptor = entityIndexBinding.getEntityIndexingInterceptor(); if ( interceptor != null ) { IndexingOverride onAdd = interceptor.onAdd( entity ); DocumentBuilderIndexedEntity docBuilder = entityIndexBinding.getDocumentBuilder(); TwoWayFieldBridge idBridge = docBuilder.getIdBridge(); String idPropertyName = docBuilder.getIdPropertyName();
DocumentBuilderIndexedEntity builder = entityIndexBinding.getDocumentBuilder(); IndexedTypeIdentifier typeIdentifier = builder.getTypeIdentifier(); searcherSimilarity = checkSimilarity( searcherSimilarity, entityIndexBinding.getSimilarity() ); if ( builder.getIdFieldName() != null ) { idFieldNames.add( builder.getIdFieldName() );
private static boolean hasElasticsearchIndexManager(ExtendedSearchIntegrator integrator, IndexedTypeSet entityTypes) { for ( IndexedTypeIdentifier entityType : entityTypes ) { EntityIndexBinding binding = integrator.getIndexBinding( entityType ); if ( binding == null ) { continue; } IndexManagerType indexManagerType = binding.getIndexManagerType(); if ( ElasticsearchIndexManagerType.INSTANCE.equals( indexManagerType ) ) { return true; } } return false; }
public MoreLikeThisBuilder( DocumentBuilderIndexedEntity documentBuilder, ExtendedSearchIntegrator searchIntegrator ) { this.documentBuilder = documentBuilder; Similarity configuredSimilarity = searchIntegrator.getIndexBindings().get( documentBuilder.getTypeIdentifier() ).getSimilarity(); if ( configuredSimilarity instanceof TFIDFSimilarity ) { this.similarity = (TFIDFSimilarity) configuredSimilarity; } else { throw log.requireTFIDFSimilarity( documentBuilder.getTypeIdentifier() ); } }
DocumentBuilderIndexedEntity builder = entityIndexBinding.getDocumentBuilder(); IndexedTypeIdentifier typeIdentifier = builder.getTypeIdentifier(); searcherSimilarity = checkSimilarity( searcherSimilarity, entityIndexBinding.getSimilarity() ); if ( builder.getIdFieldName() != null ) { idFieldNames.add( builder.getIdFieldName() );
private static boolean hasElasticsearchIndexManager(ExtendedSearchIntegrator integrator, IndexedTypeSet entityTypes) { for ( IndexedTypeIdentifier entityType : entityTypes ) { EntityIndexBinding binding = integrator.getIndexBinding( entityType ); if ( binding == null ) { continue; } IndexManagerType indexManagerType = binding.getIndexManagerType(); if ( ElasticsearchIndexManagerType.INSTANCE.equals( indexManagerType ) ) { return true; } } return false; }
public MoreLikeThisBuilder( DocumentBuilderIndexedEntity documentBuilder, ExtendedSearchIntegrator searchIntegrator ) { this.documentBuilder = documentBuilder; Similarity configuredSimilarity = searchIntegrator.getIndexBindings().get( documentBuilder.getTypeIdentifier() ).getSimilarity(); if ( configuredSimilarity instanceof TFIDFSimilarity ) { this.similarity = (TFIDFSimilarity) configuredSimilarity; } else { throw log.requireTFIDFSimilarity( documentBuilder.getTypeIdentifier() ); } }
private DocumentBuilderIndexedEntity extractDocumentBuilder(Document document) throws IOException { //maybe we can avoid document extraction: if ( singleEntityBindingIfPossible != null ) { return singleEntityBindingIfPossible.getDocumentBuilder(); } String className = document.get( ProjectionConstants.OBJECT_CLASS ); //and quite likely we can avoid the Reflect helper: EntityIndexBinding entityBinding = targetedEntityBindings.get( className ); if ( entityBinding != null ) { return entityBinding.getDocumentBuilder(); } return DocumentBuilderHelper.getDocumentBuilder( className, extendedIntegrator ); }
private void performShardAwareOperation(IndexedTypeSet entityTypes, BiConsumer<IndexManager, IndexedTypeIdentifier> operation) { for (IndexedTypeIdentifier type : entityTypes) { EntityIndexBinding indexBindingForEntity = integrator.getIndexBinding(type); if (indexBindingForEntity != null) { Set<IndexManager> indexManagers = indexBindingForEntity.getIndexManagerSelector().forExisting(type, null, null); indexManagers.forEach(im -> operation.accept(im, type)); } } } }
@Test @Category(SkipOnElasticsearch.class) // Unused AnalyzerDefs are always bound to the Lucene registry, making this test fail on ES public void shouldContainOnlyTheDefinedAnalyzers() throws Exception { ExtendedSearchIntegrator factory = sfHolder.getSearchFactory(); IndexManagerType indexManagerType = factory.getIndexBindings().get( Sample.class ).getIndexManagerType(); Map<String, AnalyzerReference> analyzerReferences = factory.getIntegration( indexManagerType ).getAnalyzerRegistry().getNamedAnalyzerReferences(); assertThat( analyzerReferences.keySet() ).containsExactlyInAnyOrder( "package-analyzer", "class-analyzer" ); Map<String, AnalyzerReference> normalizerReferences = factory.getIntegration( indexManagerType ).getNormalizerRegistry().getNamedNormalizerReferences(); assertThat( normalizerReferences.keySet() ).containsExactlyInAnyOrder( "package-normalizer", "class-normalizer" ); }
private EntityIndexingInterceptor getEntityInterceptor() { EntityIndexBinding indexBindingForEntity = extendedIntegrator.getIndexBinding( this.typeIdentifier ); return indexBindingForEntity != null ? indexBindingForEntity.getEntityIndexingInterceptor() : null; }
@Override public DocumentBuilderIndexedEntity getDocumentBuilder(IndexedTypeIdentifier type) { return indexManager.getIndexBinding( type ).getDocumentBuilder(); }
private static void collectAllIndexManagersInto(EntityIndexBinding bindings, HashMap<String, IndexManager> indexManagers) { for ( IndexManager im : bindings.getIndexManagerSelector().all() ) { indexManagers.put( im.getIndexName(), im ); } }
public HSearchEntityContext(IndexedTypeIdentifier entityType, ExtendedSearchIntegrator factory) { // get a type for meta-data retrieval; if the given type itself is not indexed, one indexed sub-type will // be used; note that this allows to e.g. query for fields not present on the given type but on one of its // sub-types, but we accept this for now indexBoundType = getIndexBoundType( entityType, factory ); if ( indexBoundType == null ) { IndexedTypeSet configuredSubTypes = factory.getConfiguredTypesPolymorphic( entityType.asTypeSet() ); if ( configuredSubTypes.isEmpty() ) { throw log.cantQueryUnconfiguredType( entityType.getName() ); } else { throw log.cantQueryUnindexedType( entityType.getName() ); } } originalAnalyzerReference = factory.getAnalyzerReference( indexBoundType ); queryAnalyzerReferenceBuilder = factory.getAnalyzerReference( indexBoundType ).startCopy(); IndexManagerType indexManagerType = factory.getIndexBinding( indexBoundType ).getIndexManagerType(); analyzerRegistry = factory.getIntegration( indexManagerType ).getAnalyzerRegistry(); }
private void index(Object entity, Session session, InstanceInitializer sessionInitializer, ConversionContext conversionContext) throws InterruptedException { Class<?> clazz = HibernateHelper.getClass( entity ); EntityIndexBinding entityIndexBinding = entityIndexBindings.get( clazz ); // it might be possible to receive not-indexes subclasses of the currently indexed type; // being not-indexed, we skip them. // FIXME for improved performance: avoid loading them in an early phase. if ( entityIndexBinding != null ) { EntityIndexingInterceptor<?> interceptor = entityIndexBinding.getEntityIndexingInterceptor(); if ( isNotSkippable( interceptor, entity ) ) { Serializable id = session.getIdentifier( entity ); AddLuceneWork addWork = createAddLuceneWork( tenantId, entity, sessionInitializer, conversionContext, id, entityIndexBinding ); backend.enqueueAsyncWork( addWork ); } } }
@Override public DocumentBuilderIndexedEntity getDocumentBuilder(IndexedTypeIdentifier type) { return indexManager.getIndexBinding( type ).getDocumentBuilder(); }
private static void collectAllIndexManagersInto(EntityIndexBinding bindings, HashMap<String, IndexManager> indexManagers) { for ( IndexManager im : bindings.getIndexManagerSelector().all() ) { indexManagers.put( im.getIndexName(), im ); } }