[hibernate-issues] [Hibernate-JIRA] Commented: (HSEARCH-159) Sort + Pagination returns wrong results.

Emmanuel Bernard (JIRA) noreply at atlassian.com
Fri Mar 7 01:20:33 EST 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-159?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_29726 ] 

Emmanuel Bernard commented on HSEARCH-159:
------------------------------------------

Could you attach a minimal test case.
Sort is applied at the Lucene level, before any kind of pagination, so the behavior you see is odd.

> Sort + Pagination returns wrong results.
> ----------------------------------------
>
>                 Key: HSEARCH-159
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-159
>             Project: Hibernate Search
>          Issue Type: Bug
>    Affects Versions: 3.0.1.GA
>         Environment: hib 3.2.5ga
>            Reporter: Jason Eacott
>
> Perhaps I am doing something wrong?
> Using the code below if I call
> getSearchResults("test",0,10); //returns incorrect data
> I get a different item at the head of the list than if I call
> getSearchResults("test",0,100);// (this one has correct data, total results for this search is 196 in my ndx & db)
> if I dont try to paginate the results then the sort items are in order and are correct.
> and if I paginate with just 1 result
> getSearchResults("test",0,1);
> and change the sort order I get the same result for each attempt: ie:
> Sort datesort=new Sort( new SortField( "date_time", SortField.STRING, true ) ); 
> and
> Sort datesort=new Sort( new SortField( "date_time", SortField.STRING, false ) );
> return the same entry -  which is NOT the correct result either. 
> This behavious seems to indicate that the data is being sorted after the limit is set
> and whats worse, if there are 50,000,000 results, even though I only want 10 and hibernate has already correctly  hydrated those 10 (albeit the wrong 10) hibernatesearch then loops over all 50,000,000 hits and creates a new (empty) hibernate proxy object for each & discard all but 10!
> ...
> 	@Field(name="date_time", index=Index.UN_TOKENIZED, store=Store.NO)
> 	@DateBridge(resolution=Resolution.MINUTE)
> 	private Date publishDate;
> ...
> public List getSearchResults(Query query,int firstResult,int maxResults) {
> 		List result=null;
> 		Session sess=null;
> 		Transaction tx = null;
> 		try {
> 			sess=getSessionFactory().openSession();
> 			FullTextSession fullTextSession = Search.createFullTextSession(sess);
> 			tx = fullTextSession.beginTransaction();
> 			tx.begin();
> 			org.hibernate.search.FullTextQuery hibQuery= fullTextSession.createFullTextQuery( query, FeedItem.class );
> 			Sort datesort=new Sort( new SortField( "date_time", SortField.STRING, true ) ); 
> 			hibQuery.setSort(datesort); 
> 				Criteria dbCr=fullTextSession.createCriteria(FeedItem.class);
> 				hibQuery.setCriteriaQuery(dbCr);
> 				dbCr.setFirstResult(firstResult);
> 				dbCr.setMaxResults(maxResults); 
> 			}
> 			long resultSize=hibQuery.getResultSize();
> 			if (resultSize>0){
> 				result = hibQuery.list()
> 			}
> 			tx.commit(); 
> 		}
> 		finally
> 		{
> 			releaseSession(sess);
> 			tx=null;
> 		}
> 		log.debug("<getSearchResults");
> 		return result;	
> 	}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list