开发者社区> 问答> 正文

hibernate search 查询数据库总数?报错

现在我用的是 hibernate search 做全文索引 索引字段是content


QueryParser queryParser = new QueryParser(Version.LUCENE_31, "content", new KeywordAnalyzer());
try {
Query query = queryParser.parse(keyword);
FullTextSession session = Search.getFullTextSession(this.getSession());
FullTextQuery fullTextQuery = session.createFullTextQuery(query, Job.class);
Criteria c = session.createCriteria(Job.class);
c.add(Restrictions.eq("cid", cid));
if(mode != 0){
c.add(Restrictions.eq("mode", mode));
}
if (btime != null && !btime.equals("") && etime != null && !etime.equals("")) {
c.add(Restrictions.gt("ctime", btime));
c.add(Restrictions.lt("ctime", etime));
}
c.setProjection(Projections.rowCount());
c.add(Restrictions.lt("ctime", lastCtime));
c.addOrder(Order.desc("ctime"));
fullTextQuery.setCriteriaQuery(c);
fullTextQuery.uniqueResult().toString();
 
return 0; 
} catch (ParseException e) {
e.printStackTrace();
}


这样用生成的sql 为

select count(*) from job where id in (?,?,?) and cid=? ........

但是现在报错说返回的是多条数据

想要达到的结果是

hibernate search 先查询索引 然后根据索引 出来的id 再加上cid做过滤总数


展开
收起
爱吃鱼的程序员 2020-06-14 18:34:51 563 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    fullTextQuery.getResultSize()

    2020-06-14 18:35:08
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
2022 DTCC-阿里云一站式数据库上云最佳实践 立即下载
云时代的数据库技术趋势 立即下载
超大型金融机构国产数据库全面迁移成功实践 立即下载