Package org.hibernate.search.engine

Examples of org.hibernate.search.engine.SearchFactory


    tx.commit();

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

    SearchFactory searchFactory = s.getSearchFactory();
    IndexReader indexReader = searchFactory.getIndexReaderAccessor().open( SpecialPerson.class );
    try {
      IndexSearcher searcher = new IndexSearcher( indexReader );
      // 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 {
      searchFactory.getIndexReaderAccessor().close( indexReader );
    }
    tx.commit();
    s.close();
  }
View Full Code Here


    int numDocsPinPoint = countSizeForType( PinPoint.class );
    return numDocsLocation == 0 && numDocsPinPoint == 0;
  }

  private int countSizeForType(Class<?> type) {
    SearchFactory searchFactory = fullTextSession.getSearchFactory();
    int numDocs = -1; // to have it fail in case of errors
    IndexReader locationIndexReader = searchFactory.getIndexReaderAccessor().open( type );
    try {
      numDocs = locationIndexReader.numDocs();
    }
    finally {
      searchFactory.getIndexReaderAccessor().close( locationIndexReader );
    }
    return numDocs;
  }
View Full Code Here

    s.clear();
    Transaction tx = s.beginTransaction();

    // Here's how to get a reader from a FullTextSession
    SearchFactory searchFactory = s.getSearchFactory();
    IndexReader reader = searchFactory.getIndexReaderAccessor().open( ElectricalProperties.class );

    /**
     * Since there are so many combinations of results here, we are only going
     * to assert a few. - J.G.
     */
    int x = 0; // only Document zero is tested: asserts rely on natural document order
    Terms termVector = reader.getTermVector( x, "content" );
    assertNotNull( termVector );
    TermsEnum iterator = termVector.iterator( null );
    BytesRef next = iterator.next(); //move to first Document: we expect it to exist
    assertNotNull( next );
    long totalTermFreq = iterator.totalTermFreq();

    assertEquals( "electrical", next.utf8ToString() );
    assertEquals( 2, totalTermFreq );

    final DocsAndPositionsEnum docsAndPositions = iterator.docsAndPositions( null, null );
    docsAndPositions.advance( 0 );//move to Document id 0

    docsAndPositions.nextPosition();
    assertEquals( 0, docsAndPositions.startOffset() );//first term in sentence
    assertEquals( 10, docsAndPositions.endOffset() );

    docsAndPositions.nextPosition();
    assertEquals( 29, docsAndPositions.startOffset() );//Term is mentioned again at character 29

    // cleanup
    for ( Object element : s.createQuery( "from " + Employee.class.getName() ).list() ) {
      s.delete( element );
    }
    searchFactory.getIndexReaderAccessor().close( reader );
    tx.commit();
    s.close();
  }
View Full Code Here

    s.clear();

    tx = s.beginTransaction();

    // Here's how to get a reader from a FullTextSession
    SearchFactory searchFactory = s.getSearchFactory();
    IndexReader reader = searchFactory.getIndexReaderAccessor().open( Employee.class );

    Terms termVector = reader.getTermVector( 0, "dept" );
    assertNull( "should not find a term position vector", termVector );

    // cleanup
    for ( Object element : s.createQuery( "from " + ElectricalProperties.class.getName() ).list() ) {
      s.delete( element );
    }
    searchFactory.getIndexReaderAccessor().close( reader );
    tx.commit();
    s.close();
  }
View Full Code Here

  public void testAccessSearchFactory() throws Exception {
    SessionFactory sessionFactory = (SessionFactory) bundleContext.getService( serviceReference );
    FullTextSession fullTextSession = Search.getFullTextSession( sessionFactory.openSession() );
    assertNotNull( "Unable to create fulltext session from ORM Session", fullTextSession );

    SearchFactory searchFactory = fullTextSession.getSearchFactory();
    assertNotNull( "Unable to access SearchFactory", searchFactory );

    assertEquals( "There should only be one indexed type", 1, searchFactory.getIndexedTypes().size() );
    assertEquals( "Wrong indexed type", Muppet.class, searchFactory.getIndexedTypes().iterator().next() );
  }
View Full Code Here

  @Override
  public SearchFactoryImplementor getSearchFactoryImpl() {
    FullTextSession s = Search.getFullTextSession( openSession() );
    s.close();
    SearchFactory searchFactory = s.getSearchFactory();
    return (SearchFactoryImplementor) searchFactory;
  }
View Full Code Here

  }

  @Test
  public void testScopedAnalyzersFromSearchFactory() throws Exception {
    FullTextSession session = Search.getFullTextSession( openSession() );
    SearchFactory searchFactory = session.getSearchFactory();
    Analyzer analyzer = searchFactory.getAnalyzer( MyEntity.class );

    // you can pass what so ever into the analysis since the used analyzers are
    // returning the same tokens all the time. We just want to make sure that
    // the right analyzers are used.
    Token[] tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "entity", "" );
    assertTokensEqual( tokens, new String[] { "alarm", "dog", "performance" } );

    tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "property", "" );
    assertTokensEqual( tokens, new String[] { "sound", "cat", "speed" } );

    tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "field", "" );
    assertTokensEqual( tokens, new String[] { "music", "elephant", "energy" } );

    tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "component.componentProperty", "" );
    assertTokensEqual( tokens, new String[] { "noise", "mouse", "light" } );

    // test border cases
    try {
      searchFactory.getAnalyzer( (Class) null );
    }
    catch (IllegalArgumentException iae) {
      log.debug( "success" );
    }

    try {
      searchFactory.getAnalyzer( String.class );
    }
    catch (IllegalArgumentException iae) {
      log.debug( "success" );
    }
View Full Code Here

  }

  @Test
  public void testNotAnalyzedFieldAndScopedAnalyzer() throws Exception {
    FullTextSession session = Search.getFullTextSession( openSession() );
    SearchFactory searchFactory = session.getSearchFactory();
    Analyzer analyzer = searchFactory.getAnalyzer( MyEntity.class );

    // you can pass what so ever into the analysis since the used analyzers are
    // returning the same tokens all the time. We just want to make sure that
    // the right analyzers are used.
    Token[] tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "notAnalyzed", "pass through" );
View Full Code Here

    int numDocsForeigner = countSizeForType( ArrayBridgeTestEntity.class );
    return numDocsForeigner == 0;
  }

  private int countSizeForType(Class<?> type) {
    SearchFactory searchFactory = fullTextSession.getSearchFactory();
    int numDocs = -1; // to have it fail in case of errors
    IndexReader locationIndexReader = searchFactory.getIndexReaderAccessor().open( type );
    try {
      numDocs = locationIndexReader.numDocs();
    }
    finally {
      searchFactory.getIndexReaderAccessor().close( locationIndexReader );
    }
    return numDocs;
  }
View Full Code Here

    int numDocsForeigner = countSizeForType( MapBridgeTestEntity.class );
    return numDocsForeigner == 0;
  }

  private int countSizeForType(Class<?> type) {
    SearchFactory searchFactory = fullTextSession.getSearchFactory();
    int numDocs = -1; // to have it fail in case of errors
    IndexReader locationIndexReader = searchFactory.getIndexReaderAccessor().open( type );
    try {
      numDocs = locationIndexReader.numDocs();
    }
    finally {
      searchFactory.getIndexReaderAccessor().close( locationIndexReader );
    }
    return numDocs;
  }
View Full Code Here

TOP

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

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.