Package org.hibernate.search

Examples of org.hibernate.search.FullTextQuery


    tx = fullTextSession.beginTransaction();

    assertEquals( "Check for deletion on Query", 0, numericQueryFor( "overriddenFieldName", 1, 6 ).size() );
    // and now check also for the real index contents:
    Query query = NumericFieldUtils.createNumericRangeQuery( "overriddenFieldName", 1, 6, true, true );
    FullTextQuery fullTextQuery = fullTextSession
        .createFullTextQuery( query, Location.class )
        .setProjection( ProjectionConstants.DOCUMENT );
    assertEquals( "Check for deletion on index projection", 0, fullTextQuery.list().size() );

    tx.commit();
  }
View Full Code Here


    tx = s.beginTransaction();


    QueryParser parser = new QueryParser( TestConstants.getTargetLuceneVersion(), "name", s.getSearchFactory().getAnalyzer( SubClass.class ) );
    org.apache.lucene.search.Query luceneQuery = parser.parse( "name:Proca\u00EFne" );
    FullTextQuery query = s.createFullTextQuery( luceneQuery, SubClass.class );
    assertEquals( 1, query.getResultSize() );

    luceneQuery = parser.parse( "name:Procaine" );
    query = s.createFullTextQuery( luceneQuery, SubClass.class );
    assertEquals( 1, query.getResultSize() );

    // make sure the result is not always 1
    luceneQuery = parser.parse( "name:foo" );
    query = s.createFullTextQuery( luceneQuery, SubClass.class );
    assertEquals( 0, query.getResultSize() );

    tx.commit();
    s.close();
  }
View Full Code Here

    tx.commit();

    tx = s.beginTransaction();
    QueryParser parser = new QueryParser( TestConstants.getTargetLuceneVersion(), "name", TestConstants.standardAnalyzer );
    Query query = parser.parse( "name:foo" );
    FullTextQuery hibQuery = s.createFullTextQuery( query );
    try {
      hibQuery.list();
      fail();
    }
    catch (SearchException e) {
      assertTrue( "Wrong message", e.getMessage().startsWith( "There are no mapped entities" ) );
    }
View Full Code Here

  private void assertView(FullTextSessionBuilder node) {
    assertEquals( slaves.size() + 1 , clusterSize( node, SimpleEmail.class ) );
    FullTextSession session = node.openFullTextSession();
    try {
      FullTextQuery fullTextQuery = session.createFullTextQuery( new MatchAllDocsQuery() );
      int resultSize = fullTextQuery.getResultSize();
      assertEquals( storedEmailsCount, resultSize );
    }
    finally {
      session.close();
    }
View Full Code Here

  private int countBooksInIndex() {
    Session session = openSession();
    FullTextSession fullTextSession = Search.getFullTextSession( session );
    fullTextSession.beginTransaction();
    FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( new MatchAllDocsQuery() );
    int size = fullTextQuery.list().size();
    fullTextSession.getTransaction().commit();
    fullTextSession.close();
    return size;
  }
View Full Code Here

    stats.clear();
    boolean enabled = stats.isStatisticsEnabled();
    if ( !enabled ) {
      stats.setStatisticsEnabled( true );
    }
    FullTextQuery hibQuery = fullTextSession.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 = fullTextSession.createFullTextQuery( query );
    List result = hibQuery.list();
    assertNotNull( result );
    assertEquals( "2 entities should be loaded", 2, stats.getEntityLoadCount() );
    if ( !enabled ) {
      stats.setStatisticsEnabled( false );
    }
View Full Code Here

        QueryParser parser = new MultiFieldQueryParser(
            TestConstants.getTargetLuceneVersion(),
            new String[] { "name", "physicalDescription", "suspectCharge" },
            TestConstants.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"
View Full Code Here

    tx = s.beginTransaction();
    FullTextSession fts = Search.getFullTextSession( s );
    QueryParser parser = new QueryParser( TestConstants.getTargetLuceneVersion(), "id", TestConstants.stopAnalyzer );

    FullTextQuery fullTextQuery = fts.createFullTextQuery( parser.parse( "body:message" ) );
    List results = fullTextQuery.list();
    assertEquals( "Query with no filter should bring back results from both shards.", 2, results.size() );

    // index is not a field on the entity; the only way to filter on this is by shard
    fullTextQuery.enableFullTextFilter( "shard" ).setParameter( "index", 0 );
    assertEquals( "Query with filter should bring back results from only one shard.", 1, fullTextQuery.list().size() );

    for ( Object o : results ) {
      s.delete( o );
    }
    tx.commit();
View Full Code Here

      QueryParser parser = new MultiFieldQueryParser(
          TestConstants.getTargetLuceneVersion(),
          new String[] { "name", "physicalDescription", "suspectCharge" },
          TestConstants.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

  //helper method
  private int countResults(Term termForQuery, FullTextSessionBuilder ftSessionBuilder, Class<?> type) {
    TermQuery fullTextQuery = new TermQuery( termForQuery );
    FullTextSession fullTextSession = ftSessionBuilder.openFullTextSession();
    Transaction transaction = fullTextSession.beginTransaction();
    FullTextQuery query = fullTextSession.createFullTextQuery( fullTextQuery, type );
    int resultSize = query.getResultSize();
    transaction.commit();
    fullTextSession.close();
    return resultSize;
  }
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.