Package org.hibernate.search.engine

Examples of org.hibernate.search.engine.SearchFactoryImplementor


    //TODO think about this scrollmode
    return scroll();
  }

  public List list() throws HibernateException {
    SearchFactoryImplementor searchFactoryImplementor = ContextHelper.getSearchFactoryBySFI( session );
    //find the directories
    IndexSearcher searcher = buildSearcher( searchFactoryImplementor );
    if ( searcher == null ) return new ArrayList( 0 );
    Hits hits;
    try {
      hits = getHits( searcher );
      int first = first();
      int max = max( first, hits );
      Session sess = (Session) this.session;

      int size = max - first + 1 < 0 ? 0 : max - first + 1;
      List<EntityInfo> infos = new ArrayList<EntityInfo>( size );
      DocumentExtractor extractor = new DocumentExtractor( searchFactoryImplementor, indexProjection );
      for (int index = first; index <= max; index++) {
        infos.add( extractor.extract( hits, index ) );
      }
      Loader loader = getLoader( sess, searchFactoryImplementor );
      List list = loader.load( infos.toArray( new EntityInfo[infos.size()] ) );
      if ( resultTransformer == null || loader instanceof ProjectionLoader) {
        //stay consistent with transformTuple which can only be executed during a projection
        return list;
      }
      else {
        return resultTransformer.transformList( list );
      }
    }
    catch (IOException e) {
      throw new HibernateException( "Unable to query Lucene index", e );
    }
    finally {
      try {
        searchFactoryImplementor.getReaderProvider().closeReader( searcher.getIndexReader() );
      }
      catch (SearchException e) {
        log.warn( "Unable to properly close searcher during lucene query: " + getQueryString(), e );
      }
    }
View Full Code Here


    setResultSize( hits );
    return hits;
  }

  private void buildFilters() {
    SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
    if ( filterDefinitions != null && filterDefinitions.size() > 0 ) {
      ChainedFilter chainedFilter = new ChainedFilter();
      for ( FullTextFilterImpl filterDefinition : filterDefinitions.values() ) {
        FilterDef def = searchFactoryImplementor.getFilterDefinition( filterDefinition.getName() );
        Class implClass = def.getImpl();
        Object instance;
        try {
          instance = implClass.newInstance();
        }
        catch (InstantiationException e) {
          throw new SearchException( "Unable to create @FullTextFilterDef: " + def.getImpl(), e );
        }
        catch (IllegalAccessException e) {
          throw new SearchException( "Unable to create @FullTextFilterDef: " + def.getImpl(), e );
        }
        for ( Map.Entry<String, Object> entry : filterDefinition.getParameters().entrySet() ) {
          def.invoke( entry.getKey(), instance, entry.getValue() );
        }
        if ( def.isCache() && def.getKeyMethod() == null && filterDefinition.getParameters().size() > 0 ) {
          throw new SearchException("Filter with parameters and no @Key method: " + filterDefinition.getName() );
        }
        FilterKey key = null;
        if ( def.isCache() ) {
          if ( def.getKeyMethod() == null ) {
            key = new FilterKey( ) {
              public int hashCode() {
                return getImpl().hashCode();
              }

              public boolean equals(Object obj) {
                if ( ! ( obj instanceof FilterKey ) ) return false;
                FilterKey that = (FilterKey) obj;
                return this.getImpl().equals( that.getImpl() );
              }
            };
          }
          else {
            try {
              key = (FilterKey) def.getKeyMethod().invoke( instance );
            }
            catch (IllegalAccessException e) {
              throw new SearchException("Unable to access @Key method: "
                  + def.getImpl().getName() + "." + def.getKeyMethod().getName() );
            }
            catch (InvocationTargetException e) {
              throw new SearchException("Unable to access @Key method: "
                  + def.getImpl().getName() + "." + def.getKeyMethod().getName() );
            }
            catch (ClassCastException e) {
              throw new SearchException("@Key method does not return FilterKey: "
                  + def.getImpl().getName() + "." + def.getKeyMethod().getName() );
            }
          }
          key.setImpl( def.getImpl() );
        }

        Filter filter = def.isCache() ?
            searchFactoryImplementor.getFilterCachingStrategy().getCachedFilter( key ) :
            null;
        if (filter == null) {
          if ( def.getFactoryMethod() != null ) {
            try {
              filter = (Filter) def.getFactoryMethod().invoke( instance );
            }
            catch (IllegalAccessException e) {
              throw new SearchException("Unable to access @Factory method: "
                  + def.getImpl().getName() + "." + def.getFactoryMethod().getName() );
            }
            catch (InvocationTargetException e) {
              throw new SearchException("Unable to access @Factory method: "
                  + def.getImpl().getName() + "." + def.getFactoryMethod().getName() );
            }
            catch (ClassCastException e) {
              throw new SearchException("@Key method does not return a org.apache.lucene.search.Filter class: "
                  + def.getImpl().getName() + "." + def.getFactoryMethod().getName() );
            }
          }
          else {
            try {
              filter = (Filter) instance;
            }
            catch (ClassCastException e) {
              throw new SearchException("@Key method does not return a org.apache.lucene.search.Filter class: "
                  + def.getImpl().getName() + "." + def.getFactoryMethod().getName() );
            }
          }
          if ( def.isCache() ) searchFactoryImplementor.getFilterCachingStrategy().addCachedFilter( key, filter );
        }
        chainedFilter.addFilter( filter );
      }
      if ( filter != null ) chainedFilter.addFilter( filter );
      filter = chainedFilter;
View Full Code Here


  public int getResultSize() {
    if ( resultSize == null ) {
      //get result size without object initialization
      SearchFactoryImplementor searchFactoryImplementor = ContextHelper.getSearchFactoryBySFI( session );
      IndexSearcher searcher = buildSearcher( searchFactoryImplementor );
      if ( searcher == null ) {
        resultSize = 0;
      }
      else {
        Hits hits;
        try {
          hits = getHits( searcher );
          resultSize = hits.length();
        }
        catch (IOException e) {
          throw new HibernateException( "Unable to query Lucene index", e );
        }
        finally {
          //searcher cannot be null
          try {
            searchFactoryImplementor.getReaderProvider().closeReader( searcher.getIndexReader() );
          }
          catch (SearchException e) {
            log.warn( "Unable to properly close searcher during lucene query: " + getQueryString(), e );
          }
        }
View Full Code Here

    //FIXME casting sucks becasue we do not control what get session from
    Session session = getSession();
    Runnable processor = null;

    try {
      SearchFactoryImplementor factory = ContextHelper.getSearchFactory( session );
      processor = factory.getBackendQueueProcessorFactory().getProcessor( queue );
    }
    finally {
      cleanSessionIfNeeded(session);
    }
    return processor;
View Full Code Here

      // step 1: create hibernate search searchFactory
      SearchConfiguration cfg = new SearchableCacheConfiguration(classes, properties);
      // set classes in the cfg

      SearchFactoryImplementor searchFactory = new SearchFactoryImpl(cfg);
//       boolean isPojoCache = c instanceof PojoCache; keep this for later usage

      // Step 2: Add cache listener to listen for events happening in the cache.
      //SearchableListener listener = isPojoCache ? new SearchablePojoListener(searchFactory) : new SearchableCoreListener(searchFactory);
View Full Code Here

    //FIXME casting sucks because we do not control what get session from
    Session session = getSession();
    Runnable processor = null;

    try {
      SearchFactoryImplementor factory = ContextHelper.getSearchFactory( session );
      processor = factory.getBackendQueueProcessorFactory().getProcessor( queue );
    }
    finally {
      cleanSessionIfNeeded(session);
    }
    return processor;
View Full Code Here

  public <T> void purgeAll(Class<T> entityType) {
    purge( entityType, null );
  }

  public void flushToIndexes() {
    SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
    searchFactoryImplementor.getWorker().flushWorks( transactionContext );
  }
View Full Code Here

  public <T> void purge(Class<T> entityType, Serializable id) {
    if ( entityType == null ) {
      return;
    }

    SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
    Set<Class<?>> targetedClasses = searchFactoryImplementor.getIndexedTypesPolymorphic( new Class[] {entityType} );
    if ( targetedClasses.isEmpty() ) {
      String msg = entityType.getName() + " is not an indexed entity or a subclass of an indexed entity";
      throw new IllegalArgumentException( msg );
    }

    Work<T> work;
    for ( Class clazz : targetedClasses ) {
      if ( id == null ) {
        work = new Work<T>( clazz, id, WorkType.PURGE_ALL );
        searchFactoryImplementor.getWorker().performWork( work, transactionContext );
      }
      else {
        work = new Work<T>( clazz, id, WorkType.PURGE );
        searchFactoryImplementor.getWorker().performWork( work, transactionContext );
      }
    }
  }
View Full Code Here

      throw new IllegalArgumentException( "Entity to index should not be null" );
    }

    Class<?> clazz = Hibernate.getClass( entity );
    //TODO cache that at the FTSession level
    SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
    //not strictly necessary but a small optimization
    if ( searchFactoryImplementor.getDocumentBuilderIndexedEntity( clazz ) == null ) {
      String msg = "Entity to index is not an @Indexed entity: " + entity.getClass().getName();
      throw new IllegalArgumentException( msg );
    }
    Serializable id = session.getIdentifier( entity );
    Work<T> work = new Work<T>( entity, id, WorkType.INDEX );
    searchFactoryImplementor.getWorker().performWork( work, transactionContext );

    //TODO
    //need to add elements in a queue kept at the Session level
    //the queue will be processed by a Lucene(Auto)FlushEventListener
    //note that we could keep this queue somewhere in the event listener in the mean time but that requires
View Full Code Here

  public <T> void purgeAll(Class<T> entityType) {
    purge( entityType, null );
  }

  public void flushToIndexes() {
    SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
    searchFactoryImplementor.getWorker().flushWorks( transactionContext );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.search.engine.SearchFactoryImplementor

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.