Package org.hibernate.search.jpa

Examples of org.hibernate.search.jpa.FullTextEntityManager


    /**
     * Flush search indexes, to be done after a reindex() or reindexAll() operation
     */
    public void flushSearchIndexes() {
        EntityManagerFactory entityManagerFactory = (EntityManagerFactory) applicationContext.getBean("entityManagerFactory");
        FullTextEntityManager fullTextEntityMgr = Search.getFullTextEntityManager(entityManagerFactory.createEntityManager());
        fullTextEntityMgr.flushToIndexes();
    }
View Full Code Here


    public void remove(PK id) {
        this.entityManager.remove(this.get(id));
    }

    public List<T> search(String searchTerm) throws SearchException {
        FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
        org.apache.lucene.search.Query qry;
        try {
            qry = HibernateSearchJpaTools.generateQuery(searchTerm, this.persistentClass, entityManager, defaultAnalyzer);
        } catch (ParseException ex) {
            throw new SearchException(ex);
        }
        org.hibernate.search.jpa.FullTextQuery hibQuery = fullTextEntityManager.createFullTextQuery(qry, this.persistentClass);
        // filter search results by owner.id value:
        // hibQuery.enableFullTextFilter("owned").setParameter("ownerId", owner.getId().toString());
        return hibQuery.getResultList();
    }
View Full Code Here

        .setParameter( "id", id )
        .getSingleResult();
  }

  public static Member findWithEmail(EntityManager em, String email) {
    FullTextEntityManager ftem = Search.getFullTextEntityManager( em );
    QueryBuilder b = ftem.getSearchFactory().buildQueryBuilder().forEntity( Member.class ).get();
    Query lq = b.keyword().wildcard().onField( "email" ).matching( email ).createQuery();
    Object uniqueResult = ftem.createFullTextQuery( lq ).getSingleResult();
    return (Member) uniqueResult;
  }
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 );
    Analyzer customAnalyzer = ftEm.getSearchFactory().getAnalyzer( "customanalyzer" );
    QueryParser parser = new MultiFieldQueryParser(
        Version.LUCENE_29, 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

        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

    emf = Persistence.createEntityManagerFactory( "hibernate-search-example" );
    em = emf.createEntityManager();
  }

  private void index() {
    FullTextEntityManager ftEm = org.hibernate.search.jpa.Search.getFullTextEntityManager( em );
    try {
      ftEm.createIndexer().startAndWait();
    }
    catch ( InterruptedException e ) {
      log.error( "Was interrupted during indexing", e );
    }
  }
View Full Code Here

      log.error( "Was interrupted during indexing", e );
    }
  }

  private void purge() {
    FullTextEntityManager ftEm = org.hibernate.search.jpa.Search.getFullTextEntityManager( em );
    ftEm.purgeAll( Book.class );
    ftEm.flushToIndexes();
    ftEm.close();
    emf.close();
  }
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

    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_33, 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

      book.title = title;
      em.persist(book);
   }

   public List<Book> findByKeyword(String keyword) {
      FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
      TermQuery termQuery = new TermQuery(new Term("title", keyword));
      FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(termQuery, Book.class);
      return fullTextQuery.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.