Package org.hibernate.search.indexes.spi

Examples of org.hibernate.search.indexes.spi.IndexManager


  }

  @Test
  public void testMultipleEntitiesPerIndex() throws Exception {
    SearchFactoryImplementor searchFactoryBySFI = ContextHelper.getSearchFactoryBySFI( (SessionFactoryImplementor) getSessionFactory() );
    IndexManager documentsIndexManager = searchFactoryBySFI.getIndexManagerHolder().getIndexManager( "Documents" );
    Assert.assertNotNull( documentsIndexManager );
    Assert.assertTrue( documentsIndexManager.getClass().equals( org.hibernate.search.indexes.impl.NRTIndexManager.class ) );
    NRTIndexManager indexManager = (NRTIndexManager) documentsIndexManager;

    Session s = getSessionFactory().openSession();
    s.getTransaction().begin();
    Document document =
View Full Code Here


    String indexName = indexBaseName;
    if ( shardName != null ) {
      indexName += INDEX_SHARD_ID_SEPARATOR + shardName;
    }

    IndexManager indexManager = indexManagersRegistry.get( indexName );
    if ( indexManager != null ) {
      indexManager.addContainedEntity( entityIndexBinding.getDocumentBuilder().getBeanClass() );
      return indexManager;
    }
    SearchFactoryImplementor searchFactory = entityIndexBinding.getSearchFactory();
    WorkerBuildContext context;
    //known implementations of SearchFactory passed are MutableSearchFactory and ImmutableSearchFactory
    if ( WorkerBuildContext.class.isAssignableFrom( searchFactory.getClass() ) ) {
      context = (WorkerBuildContext) searchFactory;
    }
    else {
      throw log.assertionFailureCannotCastToWorkerBuilderContext( searchFactory.getClass() );
    }

    Properties properties = entityIndexBinding.getProperties();
    if ( shardName != null ) {
      properties = new MaskedProperty( properties, shardName, properties );
    }

    indexManager = createIndexManager(
        indexName,
        entityIndexBinding.getDocumentBuilder().getBeanClass(),
        entityIndexBinding.getSimilarity(),
        properties,
        entityIndexBinding.getIndexManagerFactory(),
        context
    );
    indexManager.setSearchFactory( searchFactory );
    return indexManager;
  }
View Full Code Here

      Similarity indexSimilarity,
      IndexManagerFactory indexManagerFactory,
      Properties properties,
      WorkerBuildContext context) {
    String indexManagerImplementationName = properties.getProperty( Environment.INDEX_MANAGER_IMPL_NAME );
    final IndexManager manager;
    if ( StringHelper.isEmpty( indexManagerImplementationName ) ) {
      manager = indexManagerFactory.createDefaultIndexManager();
    }
    else {
      manager = indexManagerFactory.createIndexManagerByName( indexManagerImplementationName );
    }
    try {
      manager.initialize( indexName, properties, indexSimilarity, context );
      return manager;
    }
    catch (Exception e) {
      throw log.unableToInitializeIndexManager( indexName, e );
    }
View Full Code Here

    for ( int index = 0; index < nbrOfIndexManagers; index++ ) {
      String indexManagerName = nbrOfIndexManagers > 1 ?
          indexBaseName + INDEX_SHARD_ID_SEPARATOR + index :
          indexBaseName;
      Properties indexProp = indexProperties[index];
      IndexManager indexManager = indexManagersRegistry.get( indexManagerName );
      if ( indexManager == null ) {
        indexManager = createIndexManager(
            indexManagerName, mappedClass, similarity,
            indexProp, configuration.getIndexManagerFactory(), context
        );
      }
      else {
        if ( !indexManager.getSimilarity().getClass().equals( similarity.getClass() ) ) {
          throw log.getMultipleEntitiesShareIndexWithInconsistentSimilarityException(
              mappedClass.getName(),
              similarity.getClass().getName(),
              indexManager.getContainedTypes().iterator().next().getName(),
              indexManager.getSimilarity().getClass().getName()
          );
        }
        indexManager.addContainedEntity( mappedClass );
      }
      indexManagers[index] = indexManager;
    }
    return indexManagers;
  }
View Full Code Here

      Class<?> mappedClass,
      Similarity similarity,
      Properties indexProperties,
      IndexManagerFactory indexManagerFactory,
      WorkerBuildContext context) {
    IndexManager indexManager = indexManagersRegistry.get( indexManagerName );
    if ( indexManager == null ) {
      indexManager = createIndexManager(
          indexManagerName,
          similarity,
          indexManagerFactory,
          indexProperties,
          context
      );
      indexManagersRegistry.put( indexManagerName, indexManager );
    }
    indexManager.addContainedEntity( mappedClass );
    return indexManager;
  }
View Full Code Here

    IndexManager[] providers = new IndexManager[nbrOfProviders];
    for ( int index = 0; index < nbrOfProviders; index++ ) {
      String providerName = nbrOfProviders > 1 ?
          directoryProviderName + "." + index :
          directoryProviderName;
      IndexManager indexManager = indexManagersRegistry.get( providerName );
      if ( indexManager == null ) {
        indexManager = createDirectoryManager( providerName, indexProps[index], context );
        indexManagersRegistry.put( providerName, indexManager );
      }
      indexManager.addContainedEntity( mappedClass );
      providers[index] = indexManager;
    }

    //define sharding strategy for this entity:
    IndexShardingStrategy shardingStrategy;
View Full Code Here

    manager.setSimilarity( newSimilarity );
  }

  private IndexManager createDirectoryManager(String indexName, Properties indexProps, WorkerBuildContext context) {
    String indexManagerName = indexProps.getProperty( Environment.INDEX_MANAGER_IMPL_NAME, DEFAULT_INDEX_MANAGER_NAME);
    final IndexManager manager;
    if ( StringHelper.isEmpty( indexManagerName ) ) {
      manager = new DirectoryBasedIndexManager();
    }
    else {
      String longName = defaultIndexManagerClasses.get( indexManagerName );
      if ( longName == null ) {
        longName = indexManagerName;
      }
      manager = ClassLoaderHelper.instanceFromName( IndexManager.class, longName,
            IndexManagerHolder.class, "index manager" );
    }
    try {
      manager.initialize( indexName, indexProps, context );
      return manager;
    } catch (Exception e) {
      throw log.unableToInitializeIndexManager( indexName, e );
    }
  }
View Full Code Here

      return;
    }
    final ObjectMessage objectMessage = (ObjectMessage) message;
    final String indexName;
    final List<LuceneWork> queue;
    final IndexManager indexManager;
    Session session = getSession();
    SearchFactoryImplementor factory = ContextHelper.getSearchFactory( session );
    try {
      indexName = objectMessage.getStringProperty( JmsBackendQueueTask.INDEX_NAME_JMS_PROPERTY );
      indexManager = factory.getIndexManagerHolder().getIndexManager( indexName );
      if ( indexManager == null ) {
        log.messageReceivedForUndefinedIndex( indexName );
        return;
      }
      queue = indexManager.getSerializer().toLuceneWorks( (byte[]) objectMessage.getObject() );
      indexManager.performOperations( queue, null );
    }
    catch (JMSException e) {
      log.unableToRetrieveObjectFromMessage( message.getClass(), e );
      return;
    }
View Full Code Here

  private static class AddSelectionDelegate implements StreamingOperationSelectionDelegate {

    public final void performStreamOperation(LuceneWork work,
        IndexShardingStrategy shardingStrategy, IndexingMonitor monitor, boolean forceAsync) {
      IndexManager indexManager = shardingStrategy.getIndexManagerForAddition(
          work.getEntityClass(),
          work.getId(),
          work.getIdInString(),
          work.getDocument()
      );
      indexManager.performStreamOperation( work, monitor, forceAsync );
    }
View Full Code Here

  private static class AddSelectionDelegate implements ContextAwareSelectionDelegate {

    @Override
    public final void performOperation(LuceneWork work, IndexShardingStrategy shardingStrategy,
        WorkQueuePerIndexSplitter context) {
      IndexManager indexManager = shardingStrategy.getIndexManagerForAddition(
          work.getEntityClass(),
          work.getId(),
          work.getIdInString(),
          work.getDocument()
      );
View Full Code Here

TOP

Related Classes of org.hibernate.search.indexes.spi.IndexManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.