Package org.hibernate.search.jpa

Examples of org.hibernate.search.jpa.FullTextEntityManager


  @PersistenceContext
  private EntityManager em;

  @Override
  protected SearchFactory getSearchFactory() {
    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager( em );
    return fullTextEntityManager.getSearchFactory();
  }
View Full Code Here


    singer.setLastName( lastName );
    entityManager.persist( singer );
  }

  public boolean rebuildIndex() throws InterruptedException {
    FullTextEntityManager fullTextEntityManager = Search
        .getFullTextEntityManager( entityManager );
    try {
      fullTextEntityManager
          .createIndexer()
          .batchSizeToLoadObjects( 30 )
          .threadsToLoadObjects( 4 )
          .cacheMode( CacheMode.NORMAL )
          .startAndWait();
View Full Code Here

    Query query = entityManager.createQuery( "select s from Singer s" );
    return query.getResultList();
  }

  public List<?> searchAllContacts() {
    FullTextEntityManager fullTextEntityManager = Search
        .getFullTextEntityManager( entityManager );

    FullTextQuery query = fullTextEntityManager.createFullTextQuery(
        new MatchAllDocsQuery(),
        Singer.class
    );

    return query.getResultList();
View Full Code Here

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

  public void testIndex() throws Exception {
    FullTextEntityManager em = Search.createFullTextEntityManager( 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

   *
   * @throws Exception
   *             in case the test fails.
   */
  public void testSerialization() throws Exception {
    FullTextEntityManager em = Search.createFullTextEntityManager(factory
        .createEntityManager());

    indexSearchAssert(em);
   
    File tmpFile = File.createTempFile("entityManager", "ser", null);
    serializeEM(em, tmpFile);
    em = deserializeEM(tmpFile);
   
    indexSearchAssert(em);
   
    em.close();
   
    // cleanup
    tmpFile.delete();
  }
View Full Code Here

    // cleanup
    tmpFile.delete();
  }

  private FullTextEntityManager deserializeEM(File tmpFile) throws ClassNotFoundException {
    FullTextEntityManager em = null;
    FileInputStream fis = null;
    ObjectInputStream in = null;
    try {
      fis = new FileInputStream(tmpFile);
      in = new ObjectInputStream(fis);
View Full Code Here

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

  public void testQuery() throws Exception {
    FullTextEntityManager em = Search.createFullTextEntityManager( 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

        this.criteriaRules = criteriaRules;
    }

    @PostConstruct
    public void initSearcher() {
        FullTextEntityManager fullTextSession = org.hibernate.search.jpa.Search.getFullTextEntityManager(entityManager);
        start = fullTextSession.createIndexer()
                .purgeAllOnStart(true)
                .cacheMode(CacheMode.IGNORE)
                .optimizeAfterPurge(true)
                .optimizeOnFinish(true)
                .batchSizeToLoadObjects(25)
View Full Code Here

        return  count.getResultList().size();
    }


    private <T> FullTextQuery getFullTextQuery(Criteria query, Class<T> clazz, String keyword, Iterable<String> additionalFields) {
        final FullTextEntityManager session = Search.getFullTextEntityManager(entityManager);
        QueryBuilder qb = session.getSearchFactory()
                .buildQueryBuilder().forEntity(clazz).get();

        String[] searchTerms = keyword.split(" ");
        final TermMatchingContext context = qb.keyword().wildcard().onField("name");
        for (String field : additionalFields) {
            context.andField(field);
        }

        BooleanJunction<BooleanJunction> bool = qb.bool();
        for (String searchTerm : searchTerms) {
            bool.must(context.matching(String.format("*%s*", searchTerm.toLowerCase())).createQuery());
        }

        final FullTextQuery fullTextQuery = session.createFullTextQuery(bool.createQuery(), clazz);
        fullTextQuery.setCriteriaQuery(query);
        return fullTextQuery;
    }
View Full Code Here

            // オリジナルを取得し 終了日と status = M を設定する
            old.setEnded(ended);
            old.setStatus(STATUS_MODIFIED);
           
            // HibernateSearchのFulTextEntityManagerを用意。修正済みのものはインデックスから削除する by masuda-sensei
            final FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
            fullTextEntityManager.purge(DocumentModel.class, parentPk);
           
            // 関連するモジュールとイメージに同じ処理を実行する
            Collection oldModules = em.createQuery("from ModuleModel m where m.document.id = :id")
            .setParameter("id", parentPk).getResultList();
            for (Iterator iter = oldModules.iterator(); iter.hasNext(); ) {
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.