Author: epbernard
Date: 2007-07-26 12:41:36 -0400 (Thu, 26 Jul 2007)
New Revision: 12825
Modified:
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Book.java
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQuerySortTest.java
Log:
more tests with Sort
Modified: trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Book.java
===================================================================
---
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Book.java 2007-07-26
16:33:54 UTC (rev 12824)
+++
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Book.java 2007-07-26
16:41:36 UTC (rev 12825)
@@ -3,6 +3,7 @@
import java.util.Set;
import java.util.HashSet;
+import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
@@ -17,6 +18,8 @@
import org.hibernate.search.annotations.Store;
import org.hibernate.search.annotations.IndexedEmbedded;
import org.hibernate.search.annotations.Fields;
+import org.hibernate.search.annotations.Resolution;
+import org.hibernate.search.annotations.DateBridge;
/**
* @author Emmanuel Bernard
@@ -30,6 +33,7 @@
private String summary;
private Set<Author> authors = new HashSet<Author>();
private Author mainAuthor;
+ private Date publicationDate;
@IndexedEmbedded
@ManyToOne
@@ -89,4 +93,14 @@
public void setSummary(String summary) {
this.summary = summary;
}
+
+ @Field(index=Index.UN_TOKENIZED, store=Store.YES)
+ @DateBridge(resolution=Resolution.SECOND)
+ public Date getPublicationDate() {
+ return publicationDate;
+ }
+
+ public void setPublicationDate(Date publicationDate) {
+ this.publicationDate = publicationDate;
+ }
}
Modified:
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQuerySortTest.java
===================================================================
---
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQuerySortTest.java 2007-07-26
16:33:54 UTC (rev 12824)
+++
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQuerySortTest.java 2007-07-26
16:41:36 UTC (rev 12825)
@@ -2,6 +2,7 @@
package org.hibernate.search.test.query;
import java.util.List;
+import java.util.Calendar;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -86,6 +87,19 @@
assertEquals( "Wrong number of test results.", 4, result.size() );
assertEquals( "Hibernate & Lucene", result.get( 0 ).getSummary() );
+ // order by date backwards
+ query = parser.parse( "summary:lucene OR summary:action" );
+ hibQuery = s.createFullTextQuery( query, Book.class );
+ sort = new Sort( new SortField( "publicationDate", SortField.STRING, true )
); //DESC
+ hibQuery.setSort( sort );
+ result = hibQuery.list();
+ assertNotNull( result );
+ assertEquals( "Wrong number of test results.", 4, result.size() );
+ for (Book book : result) {
+ System.out.println(book.getSummary() + " : " + book.getPublicationDate() );
+ }
+ assertEquals( "Groovy in Action", result.get( 0 ).getSummary() );
+
tx.commit();
deleteTestBooks(s);
@@ -101,13 +115,22 @@
*/
private void createTestBooks(FullTextSession s) {
Transaction tx = s.beginTransaction();
+ Calendar cal = Calendar.getInstance( );
+ cal.set( 2007, 07, 25, 11, 20, 30);
Book book = new Book(1, "Hibernate & Lucene", "This is a test
book.");
+ book.setPublicationDate( cal.getTime() );
s.save(book);
+ cal.add( Calendar.SECOND, 1 );
book = new Book(2, "Hibernate & Lucene", "This is a test
book.");
+ book.setPublicationDate( cal.getTime() );
s.save(book);
+ cal.add( Calendar.SECOND, 1 );
book = new Book(3, "Hibernate & Lucene", "This is a test
book.");
+ book.setPublicationDate( cal.getTime() );
s.save(book);
+ cal.add( Calendar.SECOND, 1 );
book = new Book(4, "Groovy in Action", "The bible of Groovy");
+ book.setPublicationDate( cal.getTime() );
s.save(book);
tx.commit();
s.clear();