/** * Create an initial Lucene index for the data already present in the * database. * This method is called when Spring's startup. */ @Override public void onApplicationEvent(final ApplicationReadyEvent event) { try { FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager); fullTextEntityManager.createIndexer().startAndWait(); } catch (InterruptedException e) { System.out.println( "An error occurred trying to build the serach index: " + e.toString()); } return; }
getFullTextEntityManager(entityManager); fullTextEntityManager.getSearchFactory() .buildQueryBuilder().forEntity(User.class).get(); .keyword() .onFields("name", "city", "email") .matching(text) .createQuery(); fullTextEntityManager.createFullTextQuery(query, User.class); List<User> results = jpaQuery.getResultList();
/** * @see org.openmrs.api.db.ContextDAO#updateSearchIndexForObject(java.lang.Object) */ @Override @Transactional public void updateSearchIndexForObject(Object object) { FullTextSession session = Search.getFullTextSession(sessionFactory.getCurrentSession()); session.index(object); session.flushToIndexes(); }
/** * @param fields * @param text * @return full text query */ protected QueryBuilder getFullTextQueryBuilder() { FullTextSession fullTextSession = getFullTextSession(); return fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(getEntityClass()).get(); }
/** * @return analyzer */ public Analyzer getAnalyzer() { return super.getFullTextSession().getSearchFactory().getAnalyzer("cms"); }
/** * @see ContextDAO#updateSearchIndexAsync() */ @Override public Future<?> updateSearchIndexAsync() { try { log.info("Started asynchronously updating the search index..."); return Search.getFullTextSession(sessionFactory.getCurrentSession()).createIndexer().start(); } catch (Exception e) { throw new RuntimeException("Failed to start asynchronous search index update", e); } }
/** * @return future */ public Future<?> reCreateIndex() { FullTextSession fullTextSession = getFullTextSession(); return fullTextSession.createIndexer().start(); }
/** * @param fields * @param facetFields * @param text * @param facetCount * @return full text query */ protected FullTextQuery getFullTextQuery(org.apache.lucene.search.Query query) { FullTextSession fullTextSession = getFullTextSession(); return fullTextSession.createFullTextQuery(query, getEntityClass()); }
/** * Gives you access to the full text session. * * @return the full text session */ protected FullTextSession getFullTextSession() { return Search.getFullTextSession(getSession()); }
private void applyPartialResults(FullTextQuery fullTextQuery, Long firstResult, Long maxResults) { if (firstResult != null) { fullTextQuery.setFirstResult(firstResult.intValue()); } if (maxResults != null) { fullTextQuery.setMaxResults(maxResults.intValue()); } } }
/** * @param entity */ protected void index(E entity) { getFullTextSession().index(entity); }
/** * @see org.openmrs.api.db.hibernate.search.SearchQuery#resultSize() */ @Override public long resultSize() { if (noUniqueTerms) { return 0; } return buildQuery().getResultSize(); }
@Override public T uniqueResult() { if (noUniqueTerms) { return null; } @SuppressWarnings("unchecked") T result = (T) buildQuery().uniqueResult(); return result; }
/** * @param fields * @param text * @return full text query */ protected QueryBuilder getFullTextQueryBuilder() { FullTextSession fullTextSession = getFullTextSession(); return fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(getEntityClass()).get(); }
/** * @return analyzer */ public Analyzer getAnalyzer() { return super.getFullTextSession().getSearchFactory().getAnalyzer("cms"); }
/** * @return future */ public Future<?> reCreateIndex() { FullTextSession fullTextSession = getFullTextSession(); return fullTextSession.createIndexer().start(); }
/** * @param fields * @param facetFields * @param text * @param facetCount * @return full text query */ protected FullTextQuery getFullTextQuery(org.apache.lucene.search.Query query) { FullTextSession fullTextSession = getFullTextSession(); return fullTextSession.createFullTextQuery(query, getEntityClass()); }
/** * @param entity */ protected void index(E entity) { getFullTextSession().index(entity); }
/** * You can use it in {@link #prepareQuery()}. * * @return the query builder */ protected QueryBuilder newQueryBuilder() { return getFullTextSession().getSearchFactory().buildQueryBuilder().forEntity(getType()).get(); }
/** * You can use it in {@link #prepareQuery()}. * * @return the query parser */ protected QueryParser newQueryParser() { Analyzer analyzer = getFullTextSession().getSearchFactory().getAnalyzer(getType()); QueryParser queryParser = new QueryParser(null, analyzer); setDefaultOperator(queryParser); return queryParser; }