Examples of SearchFactoryImplementor


Examples of org.hibernate.search.engine.SearchFactoryImplementor

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

  public List list() throws HibernateException {
    SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
    //find the directories
    IndexSearcher searcher = buildSearcher( searchFactoryImplementor );
    if ( searcher == null ) {
      return Collections.EMPTY_LIST;
    }
    try {
      QueryHits queryHits = getQueryHits( searcher );
      int first = first();
      int max = max( first, queryHits.totalHits );
      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(
          queryHits, searchFactoryImplementor, indexProjection, idFieldNames, allowFieldSelectionInProjection
      );
      for ( int index = first; index <= max; index++ ) {
        infos.add( extractor.extract( 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 {
        closeSearcher( searcher, searchFactoryImplementor.getReaderProvider() );
      }
      catch ( SearchException e ) {
        log.warn( "Unable to properly close searcher during lucene query: " + getQueryString(), e );
      }
    }
View Full Code Here

Examples of org.hibernate.search.engine.SearchFactoryImplementor

    }
  }

  public Explanation explain(int documentId) {
    Explanation explanation = null;
    SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
    Searcher searcher = buildSearcher( searchFactoryImplementor );
    if ( searcher == null ) {
      throw new SearchException(
          "Unable to build explanation for document id:"
              + documentId + ". no index found"
      );
    }
    try {
      org.apache.lucene.search.Query query = filterQueryByClasses( luceneQuery );
      buildFilters();
      explanation = searcher.explain( query, documentId );
    }
    catch ( IOException e ) {
      throw new HibernateException( "Unable to query Lucene index and build explanation", e );
    }
    finally {
      //searcher cannot be null
      try {
        closeSearcher( searcher, searchFactoryImplementor.getReaderProvider() );
      }
      catch ( SearchException e ) {
        log.warn( "Unable to properly close searcher during lucene query: " + getQueryString(), e );
      }
    }
View Full Code Here

Examples of org.hibernate.search.engine.SearchFactoryImplementor

   *
   * @return the Lucene filter mapped to the filter definition
   */
  private Filter buildLuceneFilter(FullTextFilterImpl fullTextFilter) {

    SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();

    /*
     * FilterKey implementations and Filter(Factory) do not have to be threadsafe wrt their parameter injection
     * as FilterCachingStrategy ensure a memory barrier between concurrent thread calls
     */
    FilterDef def = searchFactoryImplementor.getFilterDefinition( fullTextFilter.getName() );
    Object instance = createFilterInstance( fullTextFilter, def );
    FilterKey key = createFilterKey( def, instance );

    // try to get the filter out of the cache
    Filter filter = cacheInstance( def.getCacheMode() ) ?
        searchFactoryImplementor.getFilterCachingStrategy().getCachedFilter( key ) :
        null;

    if ( filter == null ) {
      filter = createFilter( def, instance );

      // add filter to cache if we have to
      if ( cacheInstance( def.getCacheMode() ) ) {
        searchFactoryImplementor.getFilterCachingStrategy().addCachedFilter( key, filter );
      }
    }
    return filter;
  }
View Full Code Here

Examples of org.hibernate.search.engine.SearchFactoryImplementor

  }

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

Examples of org.hibernate.search.engine.SearchFactoryImplementor

  public AbstractSearch() {
    this.tClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
  }

  public List<T> list(Session session, Query query, final int from, final int maxResults) throws HibernateException {
    SearchFactoryImplementor searchFactoryImplementor = ContextHelper.getSearchFactoryBySFI((SessionImplementor) session);
    List<DirectoryProvider> targetedDirectories = new ArrayList<DirectoryProvider>();
    Map<Class<?>, DocumentBuilderIndexedEntity<?>> builders = searchFactoryImplementor.getDocumentBuildersIndexedEntities();
    for (DocumentBuilderIndexedEntity builder : builders.values()) {
      populateDirectories(targetedDirectories, builder);
    }
    final DirectoryProvider[] directoryProviders = targetedDirectories.toArray(new DirectoryProvider[targetedDirectories.size()]);
    IndexSearcher searcher = new IndexSearcher(searchFactoryImplementor.getReaderProvider().openReader(directoryProviders));

    try {
      TopDocs topDocs = searcher.search(query, Integer.MAX_VALUE);
      ScoreDoc[] scoreDocs = topDocs.scoreDocs;
      int resultSize = topDocs.totalHits;
View Full Code Here

Examples of org.hibernate.search.engine.SearchFactoryImplementor

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

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

Examples of org.hibernate.search.engine.SearchFactoryImplementor

      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

Examples of org.hibernate.search.engine.SearchFactoryImplementor

  }

  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

Examples of org.hibernate.search.engine.SearchFactoryImplementor

    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

Examples of org.hibernate.search.engine.SearchFactoryImplementor

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

  public void flushToIndexes() {
    SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
    searchFactoryImplementor.getWorker().flushWorks( transactionContext );
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.