/** * Gives you access to the full text session. * * @return the full text session */ protected FullTextSession getFullTextSession() { return Search.getFullTextSession(getSession()); }
protected FullTextSession getFullTextSession() { return Search.getFullTextSession(getSession()); }
protected FullTextSession getFullTextSession() { return Search.getFullTextSession(getSession()); }
/** * @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); } }
/** * @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(); }
/** * @see ContextDAO#updateSearchIndex() */ @Override public void updateSearchIndex() { try { log.info("Updating the search index... It may take a few minutes."); Search.getFullTextSession(sessionFactory.getCurrentSession()).createIndexer().startAndWait(); GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject( OpenmrsConstants.GP_SEARCH_INDEX_VERSION); if (gp == null) { gp = new GlobalProperty(OpenmrsConstants.GP_SEARCH_INDEX_VERSION); } gp.setPropertyValue(OpenmrsConstants.SEARCH_INDEX_VERSION.toString()); Context.getAdministrationService().saveGlobalProperty(gp); log.info("Finished updating the search index"); } catch (Exception e) { throw new RuntimeException("Failed to update the search index", e); } }
/** * Create a new fulltext session. * * @return A fulltext session attached to the current hibernate session. */ @Override public FullTextSession get() { logger.trace("Creating hibernate fulltext session."); return Search.getFullTextSession(hibernateSession); }
public void updateSearchIndexForType(Class<?> type) { FullTextSession session = Search.getFullTextSession(sessionFactory.getCurrentSession()); session.purgeAll(type);
/** * Flush search indexes, to be done after a reindex() or reindexAll() operation */ public void flushSearchIndexes() { Session currentSession = sessionFactory.getCurrentSession(); final FullTextSession fullTextSession = Search.getFullTextSession(currentSession); fullTextSession.flushToIndexes(); } }
@Override public boolean rebuildLuceneIndex() { try { FullTextSession fullTextSession = Search.getFullTextSession(sessionFactory.getCurrentSession()); fullTextSession.createIndexer().startAndWait(); } catch (InterruptedException e) { return false; } return true; }
@SuppressWarnings("unchecked") private static <T> List<T> doSearch(Session session, Class<T> clazz, Integer entityId) { FullTextSession fullTextSession = Search.getFullTextSession( session ); Transaction tx = fullTextSession.beginTransaction(); FullTextQuery query = fullTextSession.createFullTextQuery( new TermQuery( new Term( "id", entityId.toString() ) ), clazz ); List<T> result = query.list(); tx.commit(); return result; } }
@Override public SearchFactory getSearchFactory() { if ( searchFactory == null ) { //Don't use this#openSession() as that would interfere with our sanity //verification for the tests to not open additional session instances. try ( Session session = getSessionFactory().openSession() ) { searchFactory = Search.getFullTextSession( session ).getSearchFactory(); } } return searchFactory; }
private ContainingEntity doQuery(String twiceNestedEntityName) { Transaction tx = getSession().beginTransaction(); FullTextSession fullTextSession = Search.getFullTextSession( getSession() ); Query termQuery = new TermQuery( new Term( "nested.name", twiceNestedEntityName ) ); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( termQuery, ContainingEntity.class ); ContainingEntity result = (ContainingEntity) fullTextQuery.uniqueResult(); tx.commit(); return result; }
/** * @return a new FullTextSession based upon the built configuration. */ public FullTextSession openFullTextSession() { if ( sessionFactory == null ) { build(); } Session session = sessionFactory.openSession(); return Search.getFullTextSession( session ); }
@Test public void testGetResultSize() throws Exception { Session s = openSession(); FullTextSession session = Search.getFullTextSession( s ); Transaction tx = s.beginTransaction(); QueryDescriptor query = ElasticsearchQueries.fromJson( "{ 'query': { 'match' : { 'abstract' : 'Hibernate' } } }" ); FullTextQuery fullTextQuery = session.createFullTextQuery( query, ScientificArticle.class ); assertThat( fullTextQuery.getResultSize() ).isEqualTo( 4 ); tx.commit(); s.close(); }
private int getDocumentNbrFromQuery(Session currentSession) { MatchAllDocsQuery luceneQuery = new MatchAllDocsQuery(); FullTextQuery fullTextQuery = Search.getFullTextSession( currentSession ).createFullTextQuery( luceneQuery, Document.class ); return fullTextQuery.list().size(); }
private int countDocuments(String field) { FullTextSession session = Search.getFullTextSession( getSession() ); return session /** * We must use a raw Lucene query, and not use the QueryBuilder, * because the field may not exist. */ .createFullTextQuery( new WildcardQuery( new Term( field, "*" ) ) ) .getResultSize(); }
@Test public void testIndexAndSearch() throws Exception { SessionFactory sessionFactory = (SessionFactory) bundleContext.getService( serviceReference ); FullTextSession fullTextSession = Search.getFullTextSession( sessionFactory.openSession() ); assertElmoIndexed( fullTextSession, false ); persistElmo( fullTextSession ); assertElmoIndexed( fullTextSession, true ); }
private HelpItem doQuery(String tagName) { Transaction tx = getSession().beginTransaction(); FullTextSession fullTextSession = Search.getFullTextSession( getSession() ); Query termQuery = new TermQuery( new Term( "tags.tag.name", tagName ) ); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( termQuery, HelpItem.class ); HelpItem check = (HelpItem) fullTextQuery.uniqueResult(); assertNotNull( "No HelpItem with Tag '" + tagName + "' found in Lucene index.", check ); assertTrue( check.getTags().get( 0 ).getTag().getName().equals( tagName ) ); tx.commit(); return check; }
private FullTextQuery getQuery(String queryString, QueryParser parser, Session s) { Query luceneQuery = null; try { luceneQuery = parser.parse( queryString ); } catch (ParseException e) { e.printStackTrace(); } return Search.getFullTextSession( s ).createFullTextQuery( luceneQuery ); } }