@Override
 public StorageResults visit(Paging paging) {
   query.setFirstResult(paging.getStart());
   query.setFetchSize(AbstractQueryHandler.JDBC_FETCH_SIZE);
   query.setMaxResults(paging.getLimit());
   return null;
 }
Пример #2
0
  /**
   * 全文检索
   *
   * @param page 分页对象
   * @param query 关键字查询对象
   * @param queryFilter 查询过滤对象
   * @param sort 排序对象
   * @return 分页对象
   */
  @SuppressWarnings("unchecked")
  public Page<T> search(Page<T> page, BooleanQuery query, BooleanQuery queryFilter, Sort sort) {

    // 按关键字查询
    FullTextQuery fullTextQuery = getFullTextSession().createFullTextQuery(query, entityClass);

    // 过滤无效的内容
    if (queryFilter != null) {
      fullTextQuery.setFilter(new CachingWrapperFilter(new QueryWrapperFilter(queryFilter)));
    }

    // 设置排序
    if (sort != null) {
      fullTextQuery.setSort(sort);
    }

    // 定义分页
    page.setCount(fullTextQuery.getResultSize());
    fullTextQuery.setFirstResult(page.getFirstResult());
    fullTextQuery.setMaxResults(page.getMaxResults());

    // 先从持久化上下文中查找对象,如果没有再从二级缓存中查找
    fullTextQuery.initializeObjectsWith(
        ObjectLookupMethod.SECOND_LEVEL_CACHE, DatabaseRetrievalMethod.QUERY);

    // 返回结果
    page.setList(fullTextQuery.list());

    return page;
  }
Пример #3
0
  private void applyPartialResults(FullTextQuery fullTextQuery, Long firstResult, Long maxResults) {
    if (firstResult != null) {
      fullTextQuery.setFirstResult(firstResult.intValue());
    }

    if (maxResults != null) {
      fullTextQuery.setMaxResults(maxResults.intValue());
    }
  }