Package org.hibernate.search

Examples of org.hibernate.search.FullTextQuery


  public int countBusLinesByFullText() {
    FullTextSession fullTextSession = Search.getFullTextSession( openSession() );
    Transaction tx = fullTextSession.beginTransaction();
    org.apache.lucene.search.Query ftQuery = new MatchAllDocsQuery();
    FullTextQuery query = fullTextSession.createFullTextQuery( ftQuery, BusLine.class );
    int count = query.list().size();
    tx.commit();
    fullTextSession.close();
    return count;
  }
View Full Code Here


      comment = "PostgreSQL driver does not implement query timeout")
  @Test
  public void testEnoughTime() {
    Transaction tx = fts.beginTransaction();

    FullTextQuery hibernateQuery = fts.createFullTextQuery( matchAllQuery, Clock.class );
    hibernateQuery.setTimeout( 5, TimeUnit.MINUTES );
    List results = hibernateQuery.list();
    assertFalse( hibernateQuery.hasPartialResults() );
    assertEquals( 1000, results.size() );

    tx.commit();
  }
View Full Code Here

    tx.commit();
  }

  private void assertTimeoutOccursOnScroll() {
    FullTextQuery hibernateQuery = fts.createFullTextQuery( noMatchQuery, Clock.class );
    hibernateQuery.setTimeout( 10, TimeUnit.MICROSECONDS );
    try {
      hibernateQuery.scroll();
      fail( "timeout exception should happen" );
    }
    catch (QueryTimeoutException e) {
      //good
    }
View Full Code Here

    }
    fts.clear();
  }

  private void assertTimeoutOccursOnIterate() {
    FullTextQuery hibernateQuery = fts.createFullTextQuery( allSwatchClocksQuery, Clock.class );
    hibernateQuery.setTimeout( 10, TimeUnit.MICROSECONDS );

    try {
      hibernateQuery.iterate();
      fail( "timeout exception should happen" );
    }
    catch (QueryTimeoutException e) {
      //good
    }
View Full Code Here

    }
    fts.clear();
  }

  private void assertTimeoutOccursOnList() {
    FullTextQuery hibernateQuery = fts.createFullTextQuery( allSeikoClocksQuery, Clock.class );
    hibernateQuery.setTimeout( 10, TimeUnit.MICROSECONDS );
    try {
      hibernateQuery.list();
      fail( "timeout exception should happen" );
    }
    catch (QueryTimeoutException e) {
      //good
    }
View Full Code Here

    }
    fts.clear();
  }

  private void assertCorrectNumberOfClocksNoTimeout() {
    FullTextQuery hibernateQuery = fts.createFullTextQuery( allSeikoClocksQuery, Clock.class );
    final List results = hibernateQuery.list();
    assertEquals( 500, results.size() );
    fts.clear();
  }
View Full Code Here

    tx.commit();
    fts.clear();
  }

  private void assertExecutionTimeoutHasNoPartialResult() {
    FullTextQuery hibernateQuery = fts.createFullTextQuery( allSeikoClocksQuery, Clock.class );
    hibernateQuery.limitExecutionTimeTo( 30, TimeUnit.SECONDS );
    List results = hibernateQuery.list();
    assertEquals( "Test below limit termination", 500, results.size() );
    assertFalse( hibernateQuery.hasPartialResults() );
    fts.clear();
  }
View Full Code Here

    assertFalse( hibernateQuery.hasPartialResults() );
    fts.clear();
  }

  private void assertExecutionTimeoutOccursOnList() {
    FullTextQuery hibernateQuery = fts.createFullTextQuery( allSwatchClocksQuery, Clock.class );
    hibernateQuery.limitExecutionTimeTo( 1, TimeUnit.NANOSECONDS );
    List result = hibernateQuery.list();
    System.out.println( "Result size early: " + result.size() );
    assertEquals( "Test early failure, before the number of results are even fetched", 0, result.size() );
    if ( result.size() == 0 ) {
      //sometimes, this
      assertTrue( hibernateQuery.hasPartialResults() );
    }
    fts.clear();
  }
View Full Code Here

        .name( facetName )
        .onField( indexFieldName )
        .discrete()
        .createFacetingRequest();

    FullTextQuery query = fullTextSession.createFullTextQuery( luceneQuery, Car.class );
    FacetManager facetManager = query.getFacetManager();
    facetManager.enableFaceting( request );
    query.setFirstResult( 0 ).setMaxResults( 1 );
    assertEquals( "Wrong number of query matches", 13, query.getResultSize() );

    List<Facet> facetList = facetManager.getFacets( facetName );
    assertFacetCounts( facetList, new int[] { 5, 4, 4, 0 } );

    facetManager.getFacetGroup( facetName ).selectFacets( facetList.get( 0 ) );
    query.list();
    assertEquals( "Wrong number of query matches", 5, query.getResultSize() );
    List<Facet> newFacetList = facetManager.getFacets( facetName );
    assertFacetCounts( newFacetList, new int[] { 5, 0, 0, 0 } );

    facetManager.getFacetGroup( facetName ).selectFacets( facetList.get( 1 ) );
    query.setMaxResults( Integer.MAX_VALUE );
    assertEquals( "Wrong number of query matches", 9, query.list().size() );
    newFacetList = facetManager.getFacets( facetName );
    assertFacetCounts( newFacetList, new int[] { 5, 4, 0, 0 } );
  }
View Full Code Here

        .name( colorFacetName )
        .onField( colorFacetFieldName )
        .discrete()
        .createFacetingRequest();

    FullTextQuery query = createMatchAllQuery( Car.class );
    FacetManager facetManager = query.getFacetManager();
    facetManager.enableFaceting( colorFacetRequest );
    facetManager.enableFaceting( ccsFacetRequest );
    assertEquals( "Wrong number of query matches", 50, query.getResultSize() );
    assertFacetCounts( facetManager.getFacets( colorFacetName ), new int[] { 12, 12, 12, 12, 2 } );
    assertFacetCounts( facetManager.getFacets( ccsFacetName ), new int[] { 17, 16, 16, 1 } );

    Facet colorFacet = facetManager.getFacets( colorFacetName ).get( 0 );
    facetManager.getFacetGroup( colorFacetName ).selectFacets( colorFacet );
View Full Code Here

TOP

Related Classes of org.hibernate.search.FullTextQuery

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.