-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Strange test result from hibernate search on date field.
PostPosted: Fri Mar 29, 2013 1:28 am 
Regular
Regular

Joined: Fri Feb 04, 2011 8:34 pm
Posts: 66
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


Top
 Profile  
 
 Post subject: Re: Strange test result from hibernate search on date field.
PostPosted: Fri Mar 29, 2013 7:01 am 
Regular
Regular

Joined: Fri Feb 04, 2011 8:34 pm
Posts: 66
Hello,

I changed the search method with different data, and it behaves similar to the previous issue.

Here is my data setup:

Code:
ProductArticle article;
        ProductArticleFacade articleFacade = new ProductArticleFacade();
        articleFacade.setEntityManager(em);
        articleFacade.getEntityManager().getTransaction().begin();
              article = new ProductArticle();
              article.setArticleId(1);
              article.setCreationDate(date( 24, Calendar.MARCH, 2013 ));
              article.setHeader("hibernate query");
              articleFacade.create(article);
             
              article = new ProductArticle();
              article.setArticleId(2);
              article.setCreationDate(date( 14, Calendar.MARCH, 2013 ));
              article.setHeader("hibernate lucen");
              articleFacade.create(article);
             
              article = new ProductArticle();
              article.setArticleId(3);
              article.setCreationDate(date( 15, Calendar.MARCH, 2013 ));
              article.setHeader("hibernate the only tool");
              articleFacade.create(article);


test function:
Code:
public void searchPrint() throws Exception {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("TestDatePU");
        EntityManager em = emf.createEntityManager();
        ProductArticleFacade articleFacade = new ProductArticleFacade();
        articleFacade.setEntityManager(em);
        articleFacade.getEntityManager().getTransaction().begin();
            List<ProductArticle> result = articleFacade.search(em);
            assertThat( result ).as( "query result" ).hasSize( 1 );
            assertThat(result.get(0).getArticleId()).as("article_id").isEqualTo(1);
            System.out.println("0:"+result.get(0).getArticleId());
        articleFacade.getEntityManager().getTransaction().commit();
        articleFacade.getEntityManager().close();
       
    }   


The search function is shown below:

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();
       [b] org.apache.lucene.search.Query query = qb
                                .bool()
                                .must(qb.keyword().onFields("header").matching("hibernate query").createQuery())
                                .createQuery();[/b]
       
        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;
    }


Search result:

Quote:
java.lang.AssertionError: [query result] expected size:<1> but was:<9> for <[[1, hibernate query, 2013-03-24 11:05:30.0], [1, hibernate query, 2013-03-24 11:05:30.0], [1, hibernate query, 2013-03-24 11:05:30.0], [3, hibernate the only tool, 2013-03-15 11:05:30.0], [3, hibernate the only tool, 2013-03-15 11:05:30.0], [3, hibernate the only tool, 2013-03-15 11:05:30.0], [2, hibernate lucen, 2013-03-14 11:05:30.0], [2, hibernate lucen, 2013-03-14 11:05:30.0], [2, hibernate lucen, 2013-03-14 11:05:30.0]]>


Top
 Profile  
 
 Post subject: Re: Strange test result from hibernate search on date field.
PostPosted: Sat Mar 30, 2013 10:30 pm 
Regular
Regular

Joined: Fri Feb 04, 2011 8:34 pm
Posts: 66
I have posted the issue to Hibernate issue tracking website:

https://hibernate.atlassian.net/browse/HSEARCH-1290

Please review and download the sample project to review the issue.
Thanks
Sam


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.