I'm trying to return a search in a specific order. However, I'm not seeing any differences by switching ascending vs. decensing. Here is how I'm sorting:
Code:
Criteria criteria = session
.createCriteria( MessageEntity.class )
.setFetchMode( "attachments", FetchMode.JOIN )
.addOrder( ascending ? Order.asc( orderBy ) : Order.desc( orderBy ) )
.setFirstResult( start ).setMaxResults( length );
FullTextSession fullTextSession = Search.createFullTextSession( session );
FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( parser.parse( searchString ), MessageEntity.class ).setCriteriaQuery( criteria );
This is producing the following hibernate query:
Code:
select
this_.ID as ID0_1_,
this_.MESSAGE_BCC as MESSAGE2_0_1_,
... // took out a bunch of fields for brevity
attachment2_.MESSAGE_ID as MESSAGE7_1_0_,
attachment2_.CONTENT_TYPE as CONTENT6_1_0_
from
APP.MESSAGES this_
left outer join
APP.ATTACHMENTS attachment2_
on this_.ID=attachment2_.MESSAGE_ID
where
(
this_.ID in (
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
)
)
order by
this_.MESSAGE_DATE desc
I've read in the hibernate manual for search that they use the example of doing sorts with lucene, but the drawback to that is you only can search on fields that have been stored in the index. Tokenized fields are left around to sort on. However, since the hibernate query runs after the search it seems quite natural you could sort it in the DB instead of lucene which is what hibernate is doing. But, it doesn't work. It always returns it in the same order. You can see the Order by clause on the end of the statement.
I'm using Derby, Hibernate 3.3.0 GA, Hibernate Search 3.0.0 Beta 3. Any ideas what I'm doing wrong?
Charlie