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


Java Search类代码示例

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


Search类属于org.hibernate.search包,在下文中一共展示了Search类的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: emptyProductIndex

import org.hibernate.search.Search; //导入依赖的package包/类
private void emptyProductIndex() throws Exception {
    runTX(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            Session session = dm.getSession();
            if (session != null) {
                FullTextSession fullTextSession = Search
                        .getFullTextSession(session);
                fullTextSession.purgeAll(Product.class);
            }

            return null;
        }
    });

}
 
开发者ID:servicecatalog,项目名称:development,代码行数:18,代码来源:IndexRequestMasterListenerIT.java

示例6: emptySubscriptionIndex

import org.hibernate.search.Search; //导入依赖的package包/类
private void emptySubscriptionIndex() throws Exception {
    runTX(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            Session session = dm.getSession();
            if (session != null) {
                FullTextSession fullTextSession = Search
                        .getFullTextSession(session);
                fullTextSession.purgeAll(Subscription.class);
            }

            return null;
        }
    });

}
 
开发者ID:servicecatalog,项目名称:development,代码行数:18,代码来源:IndexRequestMasterListenerIT.java

示例7: 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

示例8: 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

示例9: 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

示例10: internalSave

import org.hibernate.search.Search; //导入依赖的package包/类
/**
 * This method is for internal use e. g. for updating objects without check access.
 * @param obj
 * @return the generated identifier.
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public Serializable internalSave(final O obj)
{
  Validate.notNull(obj);
  obj.setCreated();
  obj.setLastUpdate();
  onSave(obj);
  onSaveOrModify(obj);
  final Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
  final Serializable id = session.save(obj);
  log.info("New object added (" + id + "): " + obj.toString());
  prepareHibernateSearch(obj, OperationType.INSERT);
  session.flush();
  Search.getFullTextSession(session).flushToIndexes();
  afterSaveOrModify(obj);
  afterSave(obj);
  return id;
}
 
开发者ID:micromata,项目名称:projectforge-webapp,代码行数:24,代码来源:BaseDao.java

示例11: internalMarkAsDeleted

import org.hibernate.search.Search; //导入依赖的package包/类
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public void internalMarkAsDeleted(final O obj)
{
  if (obj instanceof Historizable == false) {
    log.error("Object is not historizable. Therefore marking as deleted is not supported. Please use delete instead.");
    throw new InternalErrorException();
  }
  onDelete(obj);
  final O dbObj = getHibernateTemplate().load(clazz, obj.getId(), LockMode.PESSIMISTIC_WRITE);
  onSaveOrModify(obj);
  copyValues(obj, dbObj, "deleted"); // If user has made additional changes.
  dbObj.setDeleted(true);
  dbObj.setLastUpdate();
  final Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
  session.flush();
  Search.getFullTextSession(session).flushToIndexes();
  afterSaveOrModify(obj);
  afterDelete(obj);
  getSession().flush();
  log.info("Object marked as deleted: " + dbObj.toString());
}
 
开发者ID:micromata,项目名称:projectforge-webapp,代码行数:22,代码来源:BaseDao.java

示例12: internalUndelete

import org.hibernate.search.Search; //导入依赖的package包/类
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public void internalUndelete(final O obj)
{
  final O dbObj = getHibernateTemplate().load(clazz, obj.getId(), LockMode.PESSIMISTIC_WRITE);
  onSaveOrModify(obj);
  copyValues(obj, dbObj, "deleted"); // If user has made additional changes.
  dbObj.setDeleted(false);
  obj.setDeleted(false);
  dbObj.setLastUpdate();
  obj.setLastUpdate(dbObj.getLastUpdate());
  log.info("Object undeleted: " + dbObj.toString());
  final Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
  session.flush();
  Search.getFullTextSession(session).flushToIndexes();
  afterSaveOrModify(obj);
  afterUndelete(obj);
}
 
开发者ID:micromata,项目名称:projectforge-webapp,代码行数:18,代码来源:BaseDao.java

示例13: 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

示例14: 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

示例15: 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


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