Package org.hibernate.search.jpa

Examples of org.hibernate.search.jpa.FullTextEntityManager


* @author Emmanuel Bernard
*/
public class EntityManagerTest extends JPATestCase {

  public void testQuery() throws Exception {
    FullTextEntityManager em = Search.getFullTextEntityManager( factory.createEntityManager() );
    em.getTransaction().begin();
    Bretzel bretzel = new Bretzel( 23, 34 );
    em.persist( bretzel );
    em.getTransaction().commit();
    em.clear();
    em.getTransaction().begin();
    QueryParser parser = new QueryParser( "title", new StopAnalyzer() );
    Query query = parser.parse( "saltQty:noword" );
    assertEquals( 0, em.createFullTextQuery( query ).getResultList().size() );
    query = new TermQuery( new Term("saltQty", "23.0") );
    assertEquals( "getResultList", 1, em.createFullTextQuery( query ).getResultList().size() );
    assertEquals( "getSingleResult and object retrieval", 23f,
        ( (Bretzelem.createFullTextQuery( query ).getSingleResult() ).getSaltQty() );
    assertEquals( 1, em.createFullTextQuery( query ).getResultSize() );
    em.getTransaction().commit();

    em.clear();

    em.getTransaction().begin();
    em.remove( em.find( Bretzel.class, bretzel.getId() ) );
    em.getTransaction().commit();
    em.close();
  }
View Full Code Here


    em.getTransaction().commit();
    em.close();
  }

  public void testIndex() throws Exception {
    FullTextEntityManager em = Search.getFullTextEntityManager( factory.createEntityManager() );
    em.getTransaction().begin();
    Bretzel bretzel = new Bretzel( 23, 34 );
    em.persist( bretzel );
    em.getTransaction().commit();
    em.clear();

    //Not really a unit test but a test that shows the method call without failing
    //FIXME port the index test
    em.getTransaction().begin();
    em.index( em.find( Bretzel.class, bretzel.getId() ) );
    em.getTransaction().commit();

    em.getTransaction().begin();
    em.remove( em.find( Bretzel.class, bretzel.getId() ) );
    em.getTransaction().commit();
    em.close();
  }
View Full Code Here

    }

    @Override
    public void createFullTextIndex() {
        try {
            FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
            fullTextEntityManager.createIndexer().startAndWait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
View Full Code Here

    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
    public List fullTextSearch(String filter) {
        FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
        QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Question.class).get();
        org.apache.lucene.search.Query query = qb
                .keyword()
                .onFields("title", "text", "comments.text")
                .matching(filter)
                .createQuery();

        Query persistenceQuery = fullTextEntityManager.createFullTextQuery(query, Question.class);
        return persistenceQuery.getResultList();
    }
View Full Code Here

    EntityManagerFactory entityManagerFactory;

    @Override
    public void reinitializeIndex() throws Exception {
        EntityManager em = entityManagerFactory.createEntityManager();
        FullTextEntityManager fullTextEntityManager = Search
                .getFullTextEntityManager(em);
        EntityTransaction tx = fullTextEntityManager.getTransaction();
        tx.begin();
        indexFacets(em, fullTextEntityManager,
                    "Facet_CalendarEventEntry",
                    "Facet_CallLog",
                    "Facet_FitbitActivity",
View Full Code Here

    @Override
    public List<AbstractFacet> searchFacetsIndex(long guestId, String terms)
            throws Exception {
        EntityManager em = entityManagerFactory.createEntityManager();
        FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search
                .getFullTextEntityManager(em);

        StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_31);
        org.apache.lucene.search.Query termsQuery = new QueryParser(
                Version.LUCENE_31, "fullTextDescription", analyzer)
                .parse(terms);
        org.apache.lucene.search.Query guestQuery = new QueryParser(
                Version.LUCENE_31, "guestId", analyzer)
                .parse(String.valueOf(guestId));

        BooleanQuery rootQuery = new BooleanQuery();
        rootQuery.add(new BooleanClause(guestQuery, Occur.MUST));
        rootQuery.add(new BooleanClause(termsQuery, Occur.MUST));

        // wrap Lucene query in a javax.persistence.Query
        Query persistenceQuery = fullTextEntityManager.createFullTextQuery(
                rootQuery, AbstractFacet.class);

        persistenceQuery.setMaxResults(100);

        // execute search
View Full Code Here

        boostPerField.put(bookFields[0], (float) 4);
        boostPerField.put(bookFields[1], (float) 3);
        boostPerField.put(bookFields[2], (float) 4);
        boostPerField.put(bookFields[3], (float) .5);

        FullTextEntityManager ftEm = org.hibernate.search.jpa.Search.getFullTextEntityManager((EntityManager) em);

        QueryParser parser = new MultiFieldQueryParser(bookFields, ftEm.getSearchFactory().getAnalyzer("customanalyzer"),
                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

   
   
   

    public void reindex() throws InterruptedException {
        FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
        fullTextEntityManager.createIndexer().startAndWait();
    }
View Full Code Here

    boostPerField.put( bookFields[0], (float) 4 );
    boostPerField.put( bookFields[1], (float) 3 );
    boostPerField.put( bookFields[2], (float) 4 );
    boostPerField.put( bookFields[3], (float) .5 );

    FullTextEntityManager ftEm = org.hibernate.search.jpa.Search.getFullTextEntityManager( em );
    Analyzer customAnalyzer = ftEm.getSearchFactory().getAnalyzer( "customanalyzer" );
    QueryParser parser = new MultiFieldQueryParser(
        Version.LUCENE_34, bookFields,
        customAnalyzer, 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

    return em.createQuery( "DELETE FROM RegisteredMember" ).executeUpdate();
  }

  @SuppressWarnings("unchecked")
  public List<RegisteredMember> search(String name) {
    FullTextEntityManager fullTextEm = Search.getFullTextEntityManager( em );
    Query luceneQuery = fullTextEm.getSearchFactory().buildQueryBuilder()
        .forEntity( RegisteredMember.class ).get()
        .keyword().onField( "name" ).matching( name ).createQuery();

    return fullTextEm.createFullTextQuery( luceneQuery ).getResultList();
  }
View Full Code Here

TOP

Related Classes of org.hibernate.search.jpa.FullTextEntityManager

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.