Package org.hibernate.search.engine

Examples of org.hibernate.search.engine.SearchFactoryImplementor


  ErrorHandler errorHandler;
  PolymorphicIndexHierarchy indexHierarchy;
  Map<DirectoryProvider, LuceneIndexingParameters> dirProviderIndexingParams;

  public SearchFactoryImplementor buildSearchFactory() {
    SearchFactoryImplementor searchFactoryImplementor;
    if ( rootFactory == null ) {
      if ( classes.size() > 0 ) {
        throw new SearchException( "Cannot add a class if the original SearchFactory is not passed" );
      }
      searchFactoryImplementor = buildNewSearchFactory();
View Full Code Here


  }

  private final MutableSearchFactoryState factoryState = new MutableSearchFactoryState();

  public SearchFactoryImplementor buildSearchFactory() {
    SearchFactoryImplementor searchFactoryImplementor;
    if ( rootFactory == null ) {
      if ( classes.size() > 0 ) {
        throw new SearchException( "Cannot add a class if the original SearchFactory is not passed" );
      }
      searchFactoryImplementor = buildNewSearchFactory();
View Full Code Here

   * @param entityType
   * @param id
   */
  public void purge(Class entityType, Serializable id) {
    if ( entityType == null ) return;
    SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
    // not strictly necessary but a small optimization plus let's make sure the
    // client didn't mess something up.
    Map<Class, DocumentBuilder<Object>> builders = searchFactoryImplementor.getDocumentBuilders();
    DocumentBuilder<Object> builder = builders.get( entityType );

    if ( builder == null ) {
      throw new IllegalArgumentException( entityType.getName() + " is not a mapped entity (don't forget to add @Indexed)" );
    }
    else {
      WorkType type;
      if ( id == null ) {
        type = WorkType.PURGE_ALL;
      }
      else {
        type = WorkType.PURGE;
      }
      Work work = new Work(entityType, id, type);
      searchFactoryImplementor.getWorker().performWork( work, eventSource );
    }
  }
View Full Code Here

   */
  public void index(Object entity) {
    if (entity == null) return;
    Class clazz = Hibernate.getClass( entity );
    //TODO cache that at the FTSession level
    SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
    //not strictly necessary but a small optimization
    DocumentBuilder<Object> builder = searchFactoryImplementor.getDocumentBuilders().get( clazz );
    if ( builder != null ) {
      Serializable id = session.getIdentifier( entity );
      Work work = new Work(entity, id, WorkType.INDEX);
      searchFactoryImplementor.getWorker().performWork( work, eventSource );
    }
    //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

  }

  private final MutableSearchFactoryState factoryState = new MutableSearchFactoryState();

  public SearchFactoryImplementor buildSearchFactory() {
    SearchFactoryImplementor searchFactoryImplementor;
    if ( rootFactory == null ) {
      if ( classes.size() > 0 ) {
        throw new SearchException( "Cannot add a class if the original SearchFactory is not passed" );
      }
      searchFactoryImplementor = buildNewSearchFactory();
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

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

    Class<?> clazz = HibernateHelper.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

    stream.close();
    return terms;
  }

  static DocumentBuilderIndexedEntity<?> getDocumentBuilder(QueryBuildingContext queryContext) {
    final SearchFactoryImplementor factory = queryContext.getFactory();
    final Class<?> type = queryContext.getEntityType();
    DocumentBuilderIndexedEntity<?> builder = factory.getDocumentBuilderIndexedEntity( type );
    if ( builder == null ) {
      throw new AssertionFailure( "Class in not indexed: " + type );
    }
    return builder;
  }
View Full Code Here

    //implement an interator which keep the id/class for each hit and get the object on demand
    //cause I can't keep the searcher and hence the hit opened. I dont have any hook to know when the
    //user stop using it
    //scrollable is better in this area

    SearchFactoryImplementor searchFactoryImplementor = ContextHelper.getSearchFactoryBySFI( session );
    //find the directories
    IndexSearcher searcher = buildSearcher( searchFactoryImplementor );
    if ( searcher == null ) {
      return new IteratorImpl( new ArrayList<EntityInfo>( 0 ), noLoader );
    }
    try {
      Hits 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++) {
        //TODO use indexSearcher.getIndexReader().document( hits.id(index), FieldSelector(indexProjection) );
        infos.add( extractor.extract( hits, index ) );
      }
      Loader loader = getLoader( sess, searchFactoryImplementor );
      return new IteratorImpl( infos, loader );
    }
    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

    }
  }

  public ScrollableResults scroll() throws HibernateException {
    //keep the searcher open until the resultset is closed
    SearchFactoryImplementor searchFactory = ContextHelper.getSearchFactoryBySFI( session );

    //find the directories
    IndexSearcher searcher = buildSearcher( searchFactory );
    //FIXME: handle null searcher
    Hits hits;
    try {
      hits = getHits( searcher );
      int first = first();
      int max = max( first, hits );
      DocumentExtractor extractor = new DocumentExtractor( searchFactory, indexProjection );
      Loader loader = getLoader( (Session) this.session, searchFactory );
      return new ScrollableResultsImpl( searcher, hits, first, max, fetchSize, extractor, loader, searchFactory );
    }
    catch (IOException e) {
      //close only in case of exception
      try {
        searchFactory.getReaderProvider().closeReader( searcher.getIndexReader() );
      }
      catch (SearchException ee) {
        //we have the initial issue already
      }
      throw new HibernateException( "Unable to query Lucene index", e );
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.