Package org.hibernate.search

Examples of org.hibernate.search.FullTextQuery


    tx = s.beginTransaction();
    QueryParser parser = new QueryParser( "id", new StandardAnalyzer() );
    {
      Query luceneQuery =  new MatchAllDocsQuery();
      FullTextQuery query = s.createFullTextQuery( luceneQuery );
      assertEquals( 2, query.getResultSize() );
    }
    {
      Query luceneQuery =  parser.parse( "entity:alarm" );
      FullTextQuery query = s.createFullTextQuery( luceneQuery, MyEntity.class );
      assertEquals( 1, query.getResultSize() );
    }
    {
      Query luceneQuery = parser.parse( "property:sound" );
      FullTextQuery query = s.createFullTextQuery( luceneQuery, AlarmEntity.class );
      assertEquals( 0, query.getResultSize() );
    }
   
    tx.commit();
    s.close();
  }
View Full Code Here


      // Finally create the treewalker:
      LuceneJPQLWalker walker = new LuceneJPQLWalker( treeStream, searchFactory, entityNamesResolver, namedParameters );
      walker.statement();
      org.apache.lucene.search.Query luceneQuery = walker.getLuceneQuery();
      Class targetEntity = walker.getTargetEntity();
      FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery, targetEntity );
      //Following options are mandatory to load matching entities without using a query
      //(chicken and egg problem)
      fullTextQuery.initializeObjectsWith( ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID );
      return fullTextQuery;
    }
    catch (RecognitionException e) {
      throw new HibernateException( "Invalid query syntax", e );
    }
View Full Code Here

   * the expected number of times (or fails the test)
   */
  private void assertFoundLocations(FullTextSession fullTextSession, String locationGroupName, int expectedFoundLocations) {
    final Transaction transaction = fullTextSession.beginTransaction();
    TermQuery luceneQuery = new TermQuery( new Term( "locationGroup.name", locationGroupName ) );
    FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery, Location.class );
    int resultSize = fullTextQuery.getResultSize();
    transaction.commit();

    Assert.assertEquals( expectedFoundLocations, resultSize );
  }
View Full Code Here

    // search if the record made it into the index
    tx = s.beginTransaction();
    String searchQuery = "Joe";
    QueryParser parser = new QueryParser( TestConstants.getTargetLuceneVersion(), "Content", TestConstants.standardAnalyzer );
    Query luceneQuery = parser.parse( searchQuery );
    FullTextQuery query = s.createFullTextQuery( luceneQuery );
    List results = query.list();
    assertTrue( "We should have a hit", results.size() == 1 );
    tx.commit();

    // Now try to delete
    tx = s.beginTransaction();
View Full Code Here

    FacetingRequest request = queryBuilder( Car.class ).facet()
        .name( facetName )
        .onField( indexFieldName )
        .discrete()
        .createFacetingRequest();
    FullTextQuery query = queryHondaWithFacet( request );

    List<Facet> facetList = query.getFacetManager().getFacets( facetName );
    assertEquals( "Wrong number of facets", 0, facetList.size() );
  }
View Full Code Here

    assertEquals( "Wrong number of facets", 0, facetList.size() );
  }

  private FullTextQuery queryHondaWithFacet(FacetingRequest request) {
    Query luceneQuery = queryBuilder( Car.class ).keyword().onField( "make" ).matching( "Honda" ).createQuery();
    FullTextQuery query = fullTextSession.createFullTextQuery( luceneQuery, Car.class );
    query.getFacetManager().enableFaceting( request );
    assertEquals( "Wrong number of query matches", 0, query.getResultSize() );
    return query;
  }
View Full Code Here

    fullTextSession.clear();
  }

  @SuppressWarnings("unchecked")
  private List<EntityExtendingMappedSuperclassWithCollectionField> searchEntityByCollectionValue(String value) {
    FullTextQuery query = fullTextSession.createFullTextQuery(
        new TermQuery( new Term( "collection", value ) ),
        EntityExtendingMappedSuperclassWithCollectionField.class
    );
    return query.list();
  }
View Full Code Here

      Session s = sf.openSession();
      Transaction tx = s.beginTransaction();
      QueryParser parser = new MultiFieldQueryParser(
          new String[] {"name", "physicalDescription", "suspectCharge"},
          new StandardAnalyzer() );
      FullTextQuery query = getQuery( "John Doe", parser, s );
      assertTrue( query.getResultSize() != 0 );

      query = getQuery( "green",  parser, s );
      random.nextInt( query.getResultSize() - 15 );
      query.setFirstResult( random.nextInt( query.getResultSize() - 15 ) );
      query.setMaxResults( 10 );
      query.list();
      tx.commit();
      s.close();

      s = sf.openSession();
      tx = s.beginTransaction();

      query = getQuery( "John Doe", parser, s );
      assertTrue( query.getResultSize() != 0 );

      query = getQuery( "thief",  parser, s );
      int firstResult = random.nextInt( query.getResultSize() - 15 );
      query.setFirstResult( firstResult );
      query.setMaxResults( 10 );
      List result = query.list();
      Object object = result.get(0);
      if (insert && object instanceof Detective) {
        Detective detective = (Detective) object;
        detective.setPhysicalDescription( detective.getPhysicalDescription() + " Eye" + firstResult );
      }
View Full Code Here

      Session s = sf.openSession();
      Transaction tx = s.beginTransaction();
      QueryParser parser = new MultiFieldQueryParser(
          new String[] {"name", "physicalDescription", "suspectCharge"},
          new StandardAnalyzer() );
      FullTextQuery query = getQuery( "John Doe", parser, s );
      assertTrue( query.getResultSize() != 0 );

      query = getQuery( "london",  parser, s );
      random.nextInt( query.getResultSize() - 15 );
      query.setFirstResult( random.nextInt( query.getResultSize() - 15 ) );
      query.setMaxResults( 10 );
      query.list();
      tx.commit();
      s.close();

      s = sf.openSession();
      tx = s.beginTransaction();

      getQuery( "John Doe", parser, s );
      assertTrue( query.getResultSize() != 0 );

      query = getQuery( "green",  parser, s );
      random.nextInt( query.getResultSize() - 15 );
      query.setFirstResult( random.nextInt( query.getResultSize() - 15 ) );
      query.setMaxResults( 10 );
      query.list();
      tx.commit();
      s.close();
    }
View Full Code Here

    Query query = parser.parse( "summary:Festina Or brand:Seiko" );
    Statistics stats = s.getSessionFactory().getStatistics();
    stats.clear();
    boolean enabled = stats.isStatisticsEnabled();
    if ( !enabled ) stats.setStatisticsEnabled( true );
    FullTextQuery hibQuery = s.createFullTextQuery( query, Clock.class, Book.class );
    assertEquals( "Exection of getResultSize without actual results", 2, hibQuery.getResultSize() );
    assertEquals( "No entity should be loaded", 0, stats.getEntityLoadCount() );

    query = parser.parse( "summary:Festina Or brand:Seiko" );
    hibQuery = s.createFullTextQuery( query );
    List result = hibQuery.list();
    assertNotNull( result );
    assertEquals( "2 entities should be loaded", 2, stats.getEntityLoadCount() );
    if ( !enabled ) stats.setStatisticsEnabled( false );
    for (Object element : s.createQuery( "from java.lang.Object" ).list()) s.delete( element );
    tx.commit();
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.