Hi,
Further tested hibernate search on date field, I found a strange result set returned from hibernate search.
Expected result:
Quote:
1, '2013-03-24 11:05:30', 'aaaaaaa', ,
2, '2013-03-14 11:05:30', 'bbbbb', ,
3, '2013-03-15 11:05:30', 'cccc', ,
Actual result:
Quote:
[1, aaaaaaa, 2013-03-24 11:05:30.0],
[1, aaaaaaa, 2013-03-24 11:05:30.0],
[1, aaaaaaa, 2013-03-24 11:05:30.0],
[1, aaaaaaa, 2013-03-24 11:05:30.0],
[1, aaaaaaa, 2013-03-24 11:05:30.0],
[1, aaaaaaa, 2013-03-24 11:05:30.0],
[1, aaaaaaa, 2013-03-24 11:05:30.0],
[1, aaaaaaa, 2013-03-24 11:05:30.0],
[1, aaaaaaa, 2013-03-24 11:05:30.0],
[1, aaaaaaa, 2013-03-24 11:05:30.0],
[3, cccc, 2013-03-15 11:05:30.0],
[3, cccc, 2013-03-15 11:05:30.0],
[3, cccc, 2013-03-15 11:05:30.0],
[3, cccc, 2013-03-15 11:05:30.0],
[3, cccc, 2013-03-15 11:05:30.0],
[3, cccc, 2013-03-15 11:05:30.0],
[3, cccc, 2013-03-15 11:05:30.0],
[3, cccc, 2013-03-15 11:05:30.0],
[3, cccc, 2013-03-15 11:05:30.0],
[3, cccc, 2013-03-15 11:05:30.0],
[2, bbbbb, 2013-03-14 11:05:30.0],
[2, bbbbb, 2013-03-14 11:05:30.0],
[2, bbbbb, 2013-03-14 11:05:30.0],
[2, bbbbb, 2013-03-14 11:05:30.0],
[2, bbbbb, 2013-03-14 11:05:30.0],
[2, bbbbb, 2013-03-14 11:05:30.0],
[2, bbbbb, 2013-03-14 11:05:30.0],
[2, bbbbb, 2013-03-14 11:05:30.0],
[2, bbbbb, 2013-03-14 11:05:30.0],
[2, bbbbb, 2013-03-14 11:05:30.0]]
I don't understand why the returned records are duplicated in the result.
Here is my search function:
Code:
public List<ProductArticle> search(EntityManager emp) {
// EntityManager em = emf.createEntityManager();
EntityManager em = emp;
FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
try {
fullTextEntityManager.createIndexer().startAndWait();
} catch (InterruptedException ex) {
java.util.logging.Logger.getLogger(ProductArticleFacade.class.getName()).log(Level.SEVERE, null, ex);
}
QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity( ProductArticle.class ).get();
org.apache.lucene.search.Query query = qb.all().createQuery();
Sort dateSort = new Sort(new SortField("creationDate", SortField.STRING, true)); //DESC on creationDate; false = ASC
javax.persistence.Query persistenceQuery;
persistenceQuery = fullTextEntityManager.createFullTextQuery(query, ProductArticle.class).setSort(dateSort);
List result = persistenceQuery.getResultList();
System.out.println("result:"+result.toString());
return result;
}
Environment: Hibernate 4.2.0, JBOSS 7.2.0 executed with Junit test case in Netbeans 7.2, Maven.
Any suggestion is highly appreciated.
Thanks
Sam