]
Hardy Ferentschik reopened HSEARCH-159:
---------------------------------------
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
{code}
getSearchResults("test",0,10); //returns incorrect data
{code}
I get a different item at the head of the list than if I call
{code}
getSearchResults("test",0,100);// (this one has correct data, total results for
this search is 196 in my ndx & db)
{code}
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
{code}
getSearchResults("test",0,1);
{code}
and change the sort order I get the same result for each attempt: ie:
{code}
Sort datesort=new Sort( new SortField( "date_time", SortField.STRING, true ) );
{code}
and
{code}
Sort datesort=new Sort( new SortField( "date_time", SortField.STRING, false )
);
{code}
return the same entry - which is NOT the correct result either.
This behavior 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) hibernate-search
then loops over all 50,000,000 hits and creates a new (empty) hibernate proxy object for
each & discard all but 10!
{code}
...
@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;
}
{code}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: