如何使用Lucene Search使用Hibernate搜索整数值?

时间:2016-07-10 05:38:23

标签: java hibernate lucene hibernate-search

在Integer字段上搜索时无法获取结果,数据仍然存在。谁能弄清楚我在做什么错?

 int status = 0;
 FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
 QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(ProcessActivity.class).get();
 System.out.println(""+status);
 org.apache.lucene.search.Query luceneQuery = qb.keyword().onFields("status").matching(status).createQuery();

 FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(luceneQuery, ProcessActivity.class);
 fullTextQuery.setFirstResult(0).setMaxResults(recordMaxLength);
 return fullTextQuery.getResultList();

//Following is main Entity text
@Fields({ @Field(index = Index.YES, analyze = Analyze.NO), @Field(name = "status", index = Index.YES, analyze = Analyze.NO) })
@Column(name = "STATUS")
public int getStatus() {
   return status;
}

1 个答案:

答案 0 :(得分:0)

使用NumericRangeQuery,例如

NumericRangeQuery.newIntRange("status", 1, value, value, true, true)

或字符串阶段,如

status[value TO value]