Package org.hibernate.search

Examples of org.hibernate.search.FullTextQuery


  public void runHSearch() {
    try {
      Query q = getQuery();
      // Search
      FullTextSession ftSession = Search.getFullTextSession( sf.openSession(  ) );
      final FullTextQuery textQuery = ftSession.createFullTextQuery( q, Boat.class )
          .setMaxResults( 100 ).setProjection( "name" );
      long start = System.currentTimeMillis();
      List results = textQuery.list();
      int resultSize = textQuery.getResultSize();
      long totalTime = System.currentTimeMillis() - start;
      ftSession.close();
//      log.error( "HSearch [ Thread-id : " + threadId + " ] Total time taken for search is : " + totalTime + "ms with total no. of matching records : " + resultSize );
      setTime( totalTime );
    }
View Full Code Here


    // at query time we use a standard analyzer. We explicitly search for tokens which can only be found if the
    // right language specific stemmer was used at index time
    QueryParser parser = new QueryParser( "references.text", new StandardAnalyzer() );
    org.apache.lucene.search.Query luceneQuery = parser.parse( "aufeinanderschlug" );
    FullTextQuery query = s.createFullTextQuery( luceneQuery );
    assertEquals( 1, query.getResultSize() );

    parser = new QueryParser( "text", new StandardAnalyzer() );
    luceneQuery = parser.parse( "acknowledg" );
    query = s.createFullTextQuery( luceneQuery );
    assertEquals( 1, query.getResultSize() );

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

    tx.commit();

    tx = s.beginTransaction();
    QueryParser parser = new QueryParser( "id", new StandardAnalyzer() );
    org.apache.lucene.search.Query luceneQuery = parser.parse( "entity:alarm" );
    FullTextQuery query = s.createFullTextQuery( luceneQuery, MyEntity.class );
    assertEquals( 1, query.getResultSize() );

    luceneQuery = parser.parse( "property:cat" );
    query = s.createFullTextQuery( luceneQuery, MyEntity.class );
    assertEquals( 1, query.getResultSize() );

    luceneQuery = parser.parse( "field:energy" );
    query = s.createFullTextQuery( luceneQuery, MyEntity.class );
    assertEquals( 1, query.getResultSize() );

    luceneQuery = parser.parse( "component.componentProperty:noise" );
    query = s.createFullTextQuery( luceneQuery, MyEntity.class );
    assertEquals( 1, query.getResultSize() );

    s.delete( query.uniqueResult() );
    tx.commit();

    s.close();
  }
View Full Code Here

      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

    statement.close();
    FullTextSession s = Search.getFullTextSession( sess );
    tx = s.beginTransaction();
    QueryParser parser = new QueryParser( "title", new KeywordAnalyzer() );
    Query query = parser.parse( "name:moo" );
    FullTextQuery hibQuery = s.createFullTextQuery( query, Author.class, Music.class );
    List result = hibQuery.list();
    assertEquals( "Should have returned no author", 0, result.size() );

    for (Object o : s.createCriteria( Object.class ).list()) {
      s.delete( o );
    }
View Full Code Here

      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

    super(sf, startSignal);
  }

  @Override
  protected void doAction(FullTextSession s, int jobSeed) {
    FullTextQuery q = getQuery( "John", s, Detective.class );
    List list = q.setMaxResults( 1 ).list();
    for ( Object o : list){
      Detective detective = (Detective) o;
      detective.setPhysicalDescription( "old" );
    }
  }
View Full Code Here

    super(sf, startSignal);
  }

  @Override
  protected void doAction(FullTextSession s, int jobSeed) {
    FullTextQuery q = getQuery( "John Doe", s, Detective.class);
    q.setMaxResults( 10 );
    q.getResultSize();
  }
View Full Code Here

    Query q = new TermQuery( new Term( "name", "doe" ) );
   
    assertEquals( 2, fts.createFullTextQuery( q ).getResultSize() );
    assertEquals( 2, fts.createFullTextQuery( q, Detective.class, Suspect.class ).getResultSize() );
   
    FullTextQuery detectiveQuery = fts.createFullTextQuery( q, Detective.class );
    assertEquals( 1, detectiveQuery.getResultSize() );
    assertTrue( detectiveQuery.list().get(0) instanceof Detective );
   
    FullTextQuery suspectQuery = fts.createFullTextQuery( q, Suspect.class );
    assertEquals( 1, suspectQuery.getResultSize() );
    assertTrue( suspectQuery.list().get(0) instanceof Suspect );
   
    assertEquals( 2, fts.createFullTextQuery( q ).getResultSize() );
    assertEquals( 2, fts.createFullTextQuery( q, Detective.class, Suspect.class ).getResultSize() );
   
    tx.commit();
View Full Code Here

    tx = s.beginTransaction();


    QueryParser parser = new QueryParser( "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

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.