Package org.hibernate.search.jpa

Examples of org.hibernate.search.jpa.FullTextQuery


                boostPerField);

        org.apache.lucene.search.Query luceneQuery;
        luceneQuery = parser.parse(searchQuery);

        final FullTextQuery query = ftEm.createFullTextQuery(luceneQuery, Book.class);

        return query;
    }
View Full Code Here


    em.clear();

    em.getTransaction().begin();
    final QueryBuilder builder = em.getSearchFactory().buildQueryBuilder().forEntity( Clock.class ).get();
    Query query = builder.keyword().onField( "brand" ).matching( "Seiko" ).createQuery();
    FullTextQuery hibernateQuery = em.createFullTextQuery( query, Clock.class );

    hibernateQuery.setHint( "javax.persistence.query.timeout", 100 ); //not too low or we can't reproduce it consistently
    try {
      hibernateQuery.getResultSize();
      fail( "timeout exception should happen" );
    }
    catch (QueryTimeoutException e) {
      //good
      e.printStackTrace();
View Full Code Here

    em.clear();

    em.getTransaction().begin();
    final QueryBuilder builder = em.getSearchFactory().buildQueryBuilder().forEntity( Clock.class ).get();
    Query query = builder.keyword().onField( "brand" ).matching( "Seiko" ).createQuery();
    FullTextQuery hibernateQuery = em.createFullTextQuery( query, Clock.class );
    List results = hibernateQuery.getResultList();
    assertEquals( 500, results.size() );

    em.clear();

    query = builder.keyword().onField( "brand" ).matching( "Swatch" ).createQuery();
    hibernateQuery = em.createFullTextQuery( query, Clock.class );
    hibernateQuery.limitExecutionTimeTo( 1, TimeUnit.NANOSECONDS );
    List result = hibernateQuery.getResultList();
    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() );
    }

    em.clear();

    //We cannot test intermediate limit, Lucene / hibernate: too unpredictable

//    hibernateQuery = fts.createFullTextQuery( query, Clock.class );
//    hibernateQuery.limitFetchingTime( 1000, TimeUnit.NANOSECONDS );
//    results = hibernateQuery.list();
//    System.out.println("Result size partial: " + results.size() );
//    assertTrue("Regular failure when some elements are fetched", 0 < results.size() && results.size() < 500 );
//    assertTrue( hibernateQuery.hasPartialResults() );
//
//    fts.clear();

    hibernateQuery = em.createFullTextQuery( query, Clock.class );
    hibernateQuery.limitExecutionTimeTo( 30, TimeUnit.SECONDS );
    results = hibernateQuery.getResultList();
    assertEquals( "Test below limit termination", 500, results.size() );
    assertFalse( hibernateQuery.hasPartialResults() );

    em.getTransaction().commit();

    em.clear();
View Full Code Here

    QueryParser parser = new MultiFieldQueryParser(
        TestConstants.getTargetLuceneVersion(),
        new String[] { },
        new StandardAnalyzer( TestConstants.getTargetLuceneVersion() )
    );
    FullTextQuery query = Search.getFullTextEntityManager( entityManager )
        .createFullTextQuery( parser.parse( searchQuery ), Book.class );
    return (List<Book>) query.getResultList();
  }
View Full Code Here

  }

  private int countBretzelsViaIndex(FullTextEntityManager em) {
    QueryBuilder queryBuilder = em.getSearchFactory().buildQueryBuilder().forEntity( Bretzel.class ).get();
    Query allQuery = queryBuilder.all().createQuery();
    FullTextQuery fullTextQuery = em.createFullTextQuery( allQuery, Bretzel.class );
    return fullTextQuery.getResultSize();
  }
View Full Code Here

    final QueryBuilder builder = em.getSearchFactory().buildQueryBuilder().forEntity( POI.class ).get();

    org.apache.lucene.search.Query luceneQuery = builder.spatial().onCoordinates( "location" )
        .within( 100, Unit.KM ).ofLatitude( centerLatitude ).andLongitude( centerLongitude ).createQuery();

    FullTextQuery hibQuery = em.createFullTextQuery( luceneQuery, POI.class );
    hibQuery.setProjection( FullTextQuery.THIS, FullTextQuery.SPATIAL_DISTANCE );
    hibQuery.setSpatialParameters( centerLatitude, centerLongitude, "location" );
    List results = hibQuery.getResultList();
    Object[] firstResult = (Object[]) results.get( 0 );
    Object[] secondResult = (Object[]) results.get( 1 );
    Object[] thirdResult = (Object[]) results.get( 2 );
    Object[] fourthResult = (Object[]) results.get( 3 );
    Object[] fifthResult = (Object[]) results.get( 4 );
View Full Code Here

    final QueryBuilder builder = em.getSearchFactory().buildQueryBuilder().forEntity( POI.class ).get();

    org.apache.lucene.search.Query luceneQuery = builder.spatial().onCoordinates( "location" )
        .within( 100, Unit.KM ).ofLatitude( centerLatitude ).andLongitude( centerLongitude ).createQuery();

    FullTextQuery hibQuery = em.createFullTextQuery( luceneQuery, POI.class );
    Sort distanceSort = new Sort( new DistanceSortField( centerLatitude, centerLongitude, "location" ) );
    hibQuery.setSort( distanceSort );
    hibQuery.setProjection( FullTextQuery.THIS, FullTextQuery.SPATIAL_DISTANCE );
    hibQuery.setSpatialParameters( centerLatitude, centerLongitude, "location" );
    List results = hibQuery.getResultList();
    Object[] firstResult = (Object[]) results.get( 0 );
    Object[] secondResult = (Object[]) results.get( 1 );
    Object[] thirdResult = (Object[]) results.get( 2 );
    Object[] fourthResult = (Object[]) results.get( 3 );
    Object[] fifthResult = (Object[]) results.get( 4 );
View Full Code Here

        .within( 1.8097233616663808, Unit.KM )
          .ofLatitude( centerLatitude )
          .andLongitude( centerLongitude )
        .createQuery();

    FullTextQuery hibQuery = em.createFullTextQuery( luceneQuery, POI.class );
    Sort distanceSort = new Sort( new DistanceSortField( centerLatitude, centerLongitude, "location" ) );
    hibQuery.setSort( distanceSort );
    hibQuery.setMaxResults( 1000 );
    hibQuery.setProjection( FullTextQuery.THIS, FullTextQuery.SPATIAL_DISTANCE );
    hibQuery.setSpatialParameters( centerLatitude, centerLongitude, "location" );
    List<Object[]> results = hibQuery.getResultList();

    for ( Object[] result : results ) {
      POI poi = (POI)result[0];
      String message = poi.getName() + " (" + poi.getLatitude() + ", " + poi.getLongitude() + ") is not at "
          + centerLatitude + ", " + centerLongitude;
View Full Code Here

    final QueryBuilder builder = em.getSearchFactory().buildQueryBuilder().forEntity( POI.class ).get();

    org.apache.lucene.search.Query luceneQuery = builder.spatial().onCoordinates( "location" ).within( 100, Unit.KM ).ofLatitude( centerLatitude )
        .andLongitude( centerLongitude ).createQuery();

    FullTextQuery hibQuery = em.createFullTextQuery( luceneQuery, POI.class );
    Sort distanceSort = new Sort( new DistanceSortField( centerLatitude, centerLongitude, "location" ) );
    hibQuery.setSort( distanceSort );
    hibQuery.setProjection( FullTextQuery.THIS, FullTextQuery.SPATIAL_DISTANCE );
    // Set max results to 3 when 6 documents are stored:
    hibQuery.setMaxResults( 3 );
    hibQuery.setSpatialParameters( centerLatitude, centerLongitude, "location" );
    List results = hibQuery.getResultList();
    Object[] firstResult = (Object[]) results.get( 0 );
    Object[] secondResult = (Object[]) results.get( 1 );
    Object[] thirdResult = (Object[]) results.get( 2 );
    Assert.assertEquals( (Double) firstResult[1], 0.0, 0.0001 );
    Assert.assertEquals( (Double) secondResult[1], 10.1582, 0.0001 );
View Full Code Here

        QueryParser parser =
                new QueryParser(Version.LUCENE_29, "content",
                        new StandardAnalyzer(Version.LUCENE_29));
        org.apache.lucene.search.Query textQuery = parser.parse(queryText);
        FullTextQuery ftQuery =
                entityManager.createFullTextQuery(textQuery,
                        HGlossaryTerm.class);
        ftQuery.enableFullTextFilter("glossaryLocaleFilter").setParameter(
                "locale", srcLocale);
        ftQuery.setProjection(FullTextQuery.SCORE, FullTextQuery.THIS);
        @SuppressWarnings("unchecked")
        List<Object[]> matches =
                ftQuery.setMaxResults(maxResult).getResultList();
        return matches;
    }
View Full Code Here

TOP

Related Classes of org.hibernate.search.jpa.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.