Package org.hibernate.search.reader

Examples of org.hibernate.search.reader.ReaderProvider


      throw new HibernateException("Unable to initialize index: "
          + indexFile, e);
    }
    dp = new DynamicFSDirectoryProvider(indexName, localdp.getIndexProps(),
        localdp.getSearchFactoryImplementor());
    ReaderProvider rp = localdp.getSearchFactoryImplementor()
        .getReaderProvider();
    if (rp instanceof SharedReaderProvider)
      ((SharedReaderProvider) rp).addLock(dp);
    providerMap.put(key, dp);
    return dp;
View Full Code Here


   
  }
 
  public void closeSearcher(Object query, SearchFactoryImplementor searchFactoryImplementor, IndexSearcher searcher) {
    Set<IndexReader> indexReaders = getIndexReaders( searcher );
    ReaderProvider readerProvider = searchFactoryImplementor.getReaderProvider();
    for ( IndexReader indexReader : indexReaders ) {
      try {
        readerProvider.closeReader( indexReader );
      }
      catch (SearchException e) {
        LOG.error("Cannot close Lucene Index Reader", e);
      }
    }
View Full Code Here

  }

  public int getNumberOfIndexedEntities(String entity) {
    Class<?> clazz = getEntityClass( entity );
    DirectoryProvider[] directoryProviders = searchFactoryImplementor.getDirectoryProviders( clazz );
    ReaderProvider readerProvider = searchFactoryImplementor.getReaderProvider();

    int count = 0;
    for ( DirectoryProvider directoryProvider : directoryProviders ) {
      IndexReader reader = readerProvider.openReader( directoryProvider );
      IndexSearcher searcher = new IndexSearcher( reader );
      BooleanQuery boolQuery = new BooleanQuery();
      boolQuery.add( new MatchAllDocsQuery(), BooleanClause.Occur.MUST );
      boolQuery.add(
          new TermQuery( new Term( ProjectionConstants.OBJECT_CLASS, entity ) ), BooleanClause.Occur.MUST
      );
      try {
        TopDocs topdocs = searcher.search( boolQuery, 1 );
        count += topdocs.totalHits;
      }
      catch ( IOException e ) {
        throw new RuntimeException( "Unable to execute count query for entity " + entity, e );
      }
      finally {
        readerProvider.closeReader( reader );
      }
    }
    return count;
  }
View Full Code Here

      Transaction tx = s.beginTransaction();

      // Here's how to get a reader from a FullTextSession
      SearchFactory searchFactory = s.getSearchFactory();
      DirectoryProvider provider = searchFactory.getDirectoryProviders(ElectricalProperties.class)[0];
      ReaderProvider readerProvider = searchFactory.getReaderProvider();
      IndexReader reader = readerProvider.openReader(provider);

      /**
       * Since there are so many combinations of results here, we are only going
       * to assert a few. - J.G.
       */
 
View Full Code Here

      tx = s.beginTransaction();

      // Here's how to get a reader from a FullTextSession
      SearchFactory searchFactory = s.getSearchFactory();
      DirectoryProvider provider = searchFactory.getDirectoryProviders(Employee.class)[0];
      ReaderProvider readerProvider = searchFactory.getReaderProvider();
      IndexReader reader = readerProvider.openReader(provider);

      TermPositionVector vector = (TermPositionVector) reader.getTermFreqVector(0, "dept");
      assertNull("should not find a term position vector", vector);

      //cleanup
View Full Code Here

    // Search and the record via Lucene directly
    tx = s.beginTransaction();

    DirectoryProvider directoryProvider = s.getSearchFactory().getDirectoryProviders( SpecialPerson.class )[0];
    ReaderProvider readerProvider = s.getSearchFactory().getReaderProvider();
    IndexReader reader = readerProvider.openReader( directoryProvider );
    IndexSearcher searcher = new IndexSearcher( reader );

    try {
      // we have to test using Lucene directly since query loaders will ignore hits for which there is no
      // database entry
      TopDocs topDocs = searcher.search( luceneQuery, null, 1 );
      assertTrue( "We should have no hit", topDocs.totalHits == 0 );
    }
    finally {
      readerProvider.closeReader( reader );
    }
    tx.commit();
    s.close();
  }
View Full Code Here

    // Search and the record via Lucene directly
    tx = s.beginTransaction();

    DirectoryProvider directoryProvider = s.getSearchFactory().getDirectoryProviders( SpecialPerson.class )[0];
    ReaderProvider readerProvider = s.getSearchFactory().getReaderProvider();
    IndexReader reader = readerProvider.openReader( directoryProvider );
    IndexSearcher searcher = new IndexSearcher( reader );

    try {
      // we have to test using Lucene directly since query loaders will ignore hits for which there is no
      // database entry
      TopDocs topDocs = searcher.search( luceneQuery, null, 1 );
      assertTrue( "We should have no hit", topDocs.totalHits == 0 );
    }
    finally {
      readerProvider.closeReader( reader );
    }
    tx.commit();
    s.close();
  }
View Full Code Here

    // Search and the record via Lucene directly
    tx = s.beginTransaction();

    DirectoryProvider directoryProvider = s.getSearchFactory().getDirectoryProviders( SpecialPerson.class )[0];
    ReaderProvider readerProvider = s.getSearchFactory().getReaderProvider();
    IndexReader reader = readerProvider.openReader( directoryProvider );
    IndexSearcher searcher = new IndexSearcher( reader );

    try {
      // we have to test using Lucene directly since query loaders will ignore hits for which there is no
      // database entry
      TopDocs topDocs = searcher.search( luceneQuery, null, 1 );
      assertTrue( "We should have no hit", topDocs.totalHits == 0 );
    }
    finally {
      readerProvider.closeReader( reader );
    }
    tx.commit();
    s.close();
  }
View Full Code Here

  }

  public int getNumberOfIndexedEntities(String entity) {
    Class<?> clazz = getEntityClass( entity );
    DirectoryProvider[] directoryProviders = searchFactoryImplementor.getDirectoryProviders( clazz );
    ReaderProvider readerProvider = searchFactoryImplementor.getReaderProvider();

    int count = 0;
    for ( DirectoryProvider directoryProvider : directoryProviders ) {
      IndexReader reader = readerProvider.openReader( directoryProvider );
      IndexSearcher searcher = new IndexSearcher( reader );
      BooleanQuery boolQuery = new BooleanQuery();
      boolQuery.add( new MatchAllDocsQuery(), BooleanClause.Occur.MUST );
      boolQuery.add(
          new TermQuery( new Term( ProjectionConstants.OBJECT_CLASS, entity ) ), BooleanClause.Occur.MUST
      );
      try {
        TopDocs topdocs = searcher.search( boolQuery, 1 );
        count += topdocs.totalHits;
      }
      catch ( IOException e ) {
        throw new RuntimeException( "Unable to execute count query for entity " + entity, e );
      }
      finally {
        readerProvider.closeReader( reader );
      }
    }
    return count;
  }
View Full Code Here

   * @param query toString() is invoked to display the query in the warning message
   * @param searchFactoryImplementor
   */
  public void closeSearcher(Object query, SearchFactoryImplementor searchFactoryImplementor) {
    Set<IndexReader> indexReaders = getIndexReaders( getSearcher() );
    ReaderProvider readerProvider = searchFactoryImplementor.getReaderProvider();
    for ( IndexReader indexReader : indexReaders ) {
      try {
        readerProvider.closeReader( indexReader );
      }
      catch (SearchException e) {
        //catch is inside the for loop to make sure we try to close all of them
        log.warn( "Unable to properly close searcher during lucene query: " + query.toString(), e );
      }
View Full Code Here

TOP

Related Classes of org.hibernate.search.reader.ReaderProvider

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.