当前位置: 首页>>代码示例>>Java>>正文


Java Search.getFullTextSession方法代码示例

本文整理汇总了Java中org.hibernate.search.Search.getFullTextSession方法的典型用法代码示例。如果您正苦于以下问题:Java Search.getFullTextSession方法的具体用法?Java Search.getFullTextSession怎么用?Java Search.getFullTextSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.search.Search的用法示例。


在下文中一共展示了Search.getFullTextSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: searchByTag

import org.hibernate.search.Search; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public List<PostPO> searchByTag(Paging paigng, String tag) {
	FullTextSession fullTextSession = Search.getFullTextSession(super.session());
    SearchFactory sf = fullTextSession.getSearchFactory();
    QueryBuilder qb = sf.buildQueryBuilder().forEntity(PostPO.class).get();
    org.apache.lucene.search.Query luceneQuery  = qb.phrase().onField("tags").sentence(tag).createQuery();

    FullTextQuery query = fullTextSession.createFullTextQuery(luceneQuery);
    query.setFirstResult(paigng.getFirstResult());
    query.setMaxResults(paigng.getMaxResults());

	Sort sort = new Sort(new SortField("id", SortField.Type.LONG, true));
	query.setSort(sort);
	
	paigng.setTotalCount(query.getResultSize());
	
	return query.list();
}
 
开发者ID:ThomasYangZi,项目名称:mblog,代码行数:20,代码来源:PostDaoImpl.java

示例2: sayHtmlHello

import org.hibernate.search.Search; //导入方法依赖的package包/类
@GET
@Path("/{name}")
@Produces(MediaType.TEXT_HTML)
public Response sayHtmlHello(@PathParam("name") String name) {
	String output = "<html> " + "<title>" + "Hello " + name + "</title>" + "<body><h1>" + "Hello " + name + 
			"<br>Database Index will now be rebuilt..." + 
			"<br>Please make sure the system is put into maintenance or else or the query will return nothing."
			+ "</body></h1>" + "</html> ";
	
	Session session = DBUtil.getFactory().openSession();
	FullTextSession fullTextSession = Search.getFullTextSession(session);
	try {
		System.out.println("@@ database re-indexing now begin...");
		fullTextSession.createIndexer().startAndWait();
	} catch (Exception exc) {
		exc.printStackTrace();
	}
	
	return Response.status(200).entity(output).build();
}
 
开发者ID:jeffrey-garcia,项目名称:P2P-Project,代码行数:21,代码来源:Hello.java

示例3: findAllFonds

import org.hibernate.search.Search; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.GET, value = FONDS + SLASH + "all" + SLASH)
public ResponseEntity<FondsHateoas> findAllFonds(
        final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response,
        @RequestParam(name = "filter", required = false) String filter) {

    Session session = entityManager.unwrap(Session.class);

    FullTextSession fullTextSession = Search.getFullTextSession(session);
    QueryDescriptor query = ElasticsearchQueries.fromQueryString("title:test fonds");
    List<Fonds> result = fullTextSession.createFullTextQuery(query, Fonds.class).list();

    FondsHateoas fondsHateoas = new
            FondsHateoas((ArrayList<INikitaEntity>) (ArrayList) result);
    fondsHateoasHandler.addLinks(fondsHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK)
            .allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath()))
            .body(fondsHateoas);
}
 
开发者ID:HiOA-ABI,项目名称:nikita-noark5-core,代码行数:19,代码来源:FondsHateoasController.java

示例4: handleListIndexing

import org.hibernate.search.Search; //导入方法依赖的package包/类
private void handleListIndexing(
        Collection<? extends DomainObject<?>> list) {
    Session session = getSession();
    if (list == null || session == null) {
        return;
    }

    FullTextSession fts = Search.getFullTextSession(session);
    Transaction tx = fts.beginTransaction();

    for (DomainObject<?> obj : list) {
        if (obj != null) {
            fts.index(obj);
        }
    }

    tx.commit();
}
 
开发者ID:servicecatalog,项目名称:development,代码行数:19,代码来源:IndexRequestMasterListener.java

示例5: reindexAll

import org.hibernate.search.Search; //导入方法依赖的package包/类
/**
 * Regenerates all the indexed class indexes
 *
 * @param async true if the reindexing will be done as a background thread
 * @param sess the hibernate session
 */
public static void reindexAll(boolean async, Session sess) {
    FullTextSession txtSession = Search.getFullTextSession(sess);
    MassIndexer massIndexer = txtSession.createIndexer();
    massIndexer.purgeAllOnStart(true);
    try {
        if (!async) {
            massIndexer.startAndWait();
        } else {
            massIndexer.start();
        }
    } catch (InterruptedException e) {
        log.error("mass reindexing interrupted: " + e.getMessage());
    } finally {
        txtSession.flushToIndexes();
    }
}
 
开发者ID:SMVBE,项目名称:ldadmin,代码行数:23,代码来源:HibernateSearchTools.java

示例6: testProvideDispose

import org.hibernate.search.Search; //导入方法依赖的package包/类
/**
 * Test provide and dispose.
 */
@Test
public void testProvideDispose() {
    SessionFactory sessionFactory =
            locator.getService(SessionFactory.class);
    Session hibernateSession = sessionFactory.openSession();
    FullTextSession ftSession = Search.getFullTextSession(hibernateSession);


    FulltextSearchFactoryFactory factory =
            new FulltextSearchFactoryFactory(ftSession);

    // Make sure that we can create a search factory.
    SearchFactory searchFactory = factory.provide();
    Assert.assertNotNull(searchFactory);

    // Make sure we can dispose of the factory (does nothing, sadly).
    factory.dispose(searchFactory);

    if (hibernateSession.isOpen()) {
        hibernateSession.close();
    }
}
 
开发者ID:krotscheck,项目名称:jersey2-toolkit,代码行数:26,代码来源:FulltextSearchFactoryFactoryTest.java

示例7: reindexMassIndexer

import org.hibernate.search.Search; //导入方法依赖的package包/类
/**
 * 
 * @param clazz
 */
private long reindexMassIndexer(final Class< ? > clazz)
{
  final Session session = getSession();
  final Criteria criteria = createCriteria(session, clazz, null, true);
  final Long number = (Long) criteria.uniqueResult(); // Get number of objects to re-index (select count(*) from).
  log.info("Starting (mass) re-indexing of " + number + " entries of type " + clazz.getName() + "...");
  final FullTextSession fullTextSession = Search.getFullTextSession(session);
  try {
    fullTextSession.createIndexer(clazz)//
    .batchSizeToLoadObjects(25) //
    //.cacheMode(CacheMode.NORMAL) //
    .threadsToLoadObjects(5) //
    //.threadsForIndexWriter(1) //
    .threadsForSubsequentFetching(20) //
    .startAndWait();
  } catch (final InterruptedException ex) {
    log.error("Exception encountered while reindexing: " + ex.getMessage(), ex);
  }
  final SearchFactory searchFactory = fullTextSession.getSearchFactory();
  searchFactory.optimize(clazz);
  log.info("Re-indexing of " + number + " objects of type " + clazz.getName() + " done.");
  return number;
}
 
开发者ID:micromata,项目名称:projectforge-webapp,代码行数:28,代码来源:DatabaseDao.java

示例8: handleListIndexing

import org.hibernate.search.Search; //导入方法依赖的package包/类
private void handleListIndexing(Collection<? extends DomainObject<?>> list,
        Session session) {
    if (list == null || session == null) {
        return;
    }

    FullTextSession fts = Search.getFullTextSession(session);

    for (DomainObject<?> obj : list) {
        if (obj != null) {
            fts.index(obj);
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:15,代码来源:HibernateIndexer.java

示例9: handleObjectIndexing

import org.hibernate.search.Search; //导入方法依赖的package包/类
private void handleObjectIndexing(Object parameter, Session session) {

        if (parameter == null || session == null) {
            return;
        }

        FullTextSession fts = Search.getFullTextSession(session);
        fts.index(parameter);
    }
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:10,代码来源:HibernateIndexer.java

示例10: applyQueryImpl

import org.hibernate.search.Search; //导入方法依赖的package包/类
protected void applyQueryImpl(Query query) {
    EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(emf);
    if (em == null) {
        entityManager = emf.createEntityManager();
        em = entityManager;
    }
    FullTextSession fullTextSession = Search.getFullTextSession(em.unwrap(Session.class));
    fullTextQuery = fullTextSession.createFullTextQuery(query, entityClass);
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:10,代码来源:JpaDatasourceMapper.java

示例11: search

import org.hibernate.search.Search; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public List<Post> search(Paging paging, String q) throws Exception {
	FullTextSession fullTextSession = Search.getFullTextSession(super.session());
    SearchFactory sf = fullTextSession.getSearchFactory();
    QueryBuilder qb = sf.buildQueryBuilder().forEntity(PostPO.class).get();

	org.apache.lucene.search.Query luceneQuery  = qb.keyword().onFields("title","summary","tags").matching(q).createQuery();

	FullTextQuery query = fullTextSession.createFullTextQuery(luceneQuery);
    query.setFirstResult(paging.getFirstResult());
    query.setMaxResults(paging.getMaxResults());

    StandardAnalyzer standardAnalyzer = new StandardAnalyzer();
    SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span style='color:red;'>", "</span>");
       QueryScorer queryScorer = new QueryScorer(luceneQuery);
       Highlighter highlighter = new Highlighter(formatter, queryScorer);
       
	List<PostPO> list = query.list();
    List<Post> rets = new ArrayList<>(list.size());

    for (PostPO po : list) {
		Post m = BeanMapUtils.copy(po, 0);

		// 处理高亮
		String title = highlighter.getBestFragment(standardAnalyzer, "title", m.getTitle());
		String summary = highlighter.getBestFragment(standardAnalyzer, "summary", m.getSummary());

		if (StringUtils.isNotEmpty(title)) {
			m.setTitle(title);
		}
		if (StringUtils.isNotEmpty(summary)) {
			m.setSummary(summary);
		}
		rets.add(m);
	}

	paging.setTotalCount(query.getResultSize());
	return rets;
}
 
开发者ID:ThomasYangZi,项目名称:mblog,代码行数:41,代码来源:PostDaoImpl.java

示例12: optimizeIndexes

import org.hibernate.search.Search; //导入方法依赖的package包/类
/**
 * Do real indexes optimization.
 */
public static void optimizeIndexes() throws Exception {
	FullTextSession ftSession = null;
	Session session = null;

	if (optimizeIndexesRunning) {
		log.warn("*** Optimize indexes already running ***");
	} else {
		optimizeIndexesRunning = true;
		log.debug("*** Begin optimize indexes ***");

		try {
			session = HibernateUtil.getSessionFactory().openSession();
			ftSession = Search.getFullTextSession(session);

			// Optimize indexes
			SearchFactory searchFactory = ftSession.getSearchFactory();
			searchFactory.optimize();
		} catch (Exception e) {
			throw e;
		} finally {
			optimizeIndexesRunning = false;
			HibernateUtil.close(ftSession);
			HibernateUtil.close(session);
		}

		log.debug("*** End optimize indexes ***");
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:32,代码来源:RebuildIndexesServlet.java

示例13: findUserByPhoneNumber

import org.hibernate.search.Search; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public User findUserByPhoneNumber(String phoneNumber) {
	User user = null;
	if (!StringUtil.isEmpty(phoneNumber)) {
		Session session = DBUtil.getFactory().openSession();
		FullTextSession fullTextSession = Search.getFullTextSession(session);
		try {	
			// not necessary if database index is presence already
			//fullTextSession.createIndexer().startAndWait(); 
			
			StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_35);
			BooleanQuery finalQuery = new BooleanQuery();
			QueryParser queryParser = new QueryParser(Version.LUCENE_35, UserConstants.DOMAIN_NAME_PHONE, analyzer);
			Query query = queryParser.parse(phoneNumber);
			finalQuery.add(query, Occur.MUST);
			org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(finalQuery);
			List<User> result = hibQuery.list();
			if (result != null && result.size() > 0) {
				user = result.get(0);
			} else {
				LoggerUtil.info(this.getClass().getName(), "No user with phone number = " + phoneNumber + " can be found.");
			}
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} finally {
			fullTextSession.disconnect();
			session.disconnect();
		}
	}
	return user;
}
 
开发者ID:jeffrey-garcia,项目名称:P2P-Project,代码行数:33,代码来源:UserDao.java

示例14: handleObjectIndexing

import org.hibernate.search.Search; //导入方法依赖的package包/类
private void handleObjectIndexing(Object parameter) {

        Session session = getSession();
        if (parameter == null || session == null) {
            return;
        }

        FullTextSession fts = Search.getFullTextSession(session);
        Transaction tx = fts.beginTransaction();

        fts.index(parameter);

        tx.commit();
    }
 
开发者ID:servicecatalog,项目名称:development,代码行数:15,代码来源:IndexRequestMasterListener.java

示例15: rebuildSearchIndexes

import org.hibernate.search.Search; //导入方法依赖的package包/类
@Override
	public void rebuildSearchIndexes()
	{
		// For some reason this generates an exception, something about unable
		// to synchronize transactions
//		FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
//		try
//		{
//			fullTextEntityManager.createIndexer().startAndWait();
//		}
//		catch (InterruptedException e) { throw new RuntimeException(e); }

		// This alternative code (from the Hibernate Search docs) seems to work
		// although it generates a warning message when complete.  Not going to
		// worry about it, this code doesn't run often.
		final int BATCH_SIZE = 128;
		org.hibernate.Session session = ((EntityManagerImpl)this.em.getDelegate()).getSession();		
		FullTextSession fullTextSession = Search.getFullTextSession(session);
		fullTextSession.setFlushMode(FlushMode.MANUAL);
		fullTextSession.setCacheMode(CacheMode.IGNORE);
		Transaction transaction = fullTextSession.beginTransaction();
		//Scrollable results will avoid loading too many objects in memory
		ScrollableResults results = fullTextSession.createCriteria(Mail.class)
		    .setFetchSize(BATCH_SIZE)
		    .scroll(ScrollMode.FORWARD_ONLY);
		int index = 0;
		while (results.next())
		{
		    index++;
		    fullTextSession.index(results.get(0)); //index each element
		    if (index % BATCH_SIZE == 0) {
		        fullTextSession.flushToIndexes(); //apply changes to indexes
		        fullTextSession.clear(); //free memory since the queue is processed
		    }
		}
		transaction.commit();	
	}
 
开发者ID:voodoodyne,项目名称:subetha,代码行数:38,代码来源:AdminBean.java


注:本文中的org.hibernate.search.Search.getFullTextSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。