Author: epbernard
Date: 2008-06-03 16:47:14 -0400 (Tue, 03 Jun 2008)
New Revision: 14732
Modified:
search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java
search/trunk/src/test/org/hibernate/search/test/query/Employee.java
search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java
Log:
HSEARCH-207 Make all DateBridge TwoWay
Modified: search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java 2008-06-03
20:10:07 UTC (rev 14731)
+++ search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java 2008-06-03
20:47:14 UTC (rev 14732)
@@ -69,12 +69,12 @@
public static final TwoWayFieldBridge Uri = new TwoWayString2FieldBridgeAdaptor( new
UriBridge() );
- public static final FieldBridge DATE_YEAR = new String2FieldBridgeAdaptor(
DateBridge.DATE_YEAR );
- public static final FieldBridge DATE_MONTH = new String2FieldBridgeAdaptor(
DateBridge.DATE_MONTH );
- public static final FieldBridge DATE_DAY = new String2FieldBridgeAdaptor(
DateBridge.DATE_DAY );
- public static final FieldBridge DATE_HOUR = new String2FieldBridgeAdaptor(
DateBridge.DATE_HOUR );
- public static final FieldBridge DATE_MINUTE = new String2FieldBridgeAdaptor(
DateBridge.DATE_MINUTE );
- public static final FieldBridge DATE_SECOND = new String2FieldBridgeAdaptor(
DateBridge.DATE_SECOND );
+ public static final FieldBridge DATE_YEAR = new TwoWayString2FieldBridgeAdaptor(
DateBridge.DATE_YEAR );
+ public static final FieldBridge DATE_MONTH = new TwoWayString2FieldBridgeAdaptor(
DateBridge.DATE_MONTH );
+ public static final FieldBridge DATE_DAY = new TwoWayString2FieldBridgeAdaptor(
DateBridge.DATE_DAY );
+ public static final FieldBridge DATE_HOUR = new TwoWayString2FieldBridgeAdaptor(
DateBridge.DATE_HOUR );
+ public static final FieldBridge DATE_MINUTE = new TwoWayString2FieldBridgeAdaptor(
DateBridge.DATE_MINUTE );
+ public static final FieldBridge DATE_SECOND = new TwoWayString2FieldBridgeAdaptor(
DateBridge.DATE_SECOND );
public static final TwoWayFieldBridge DATE_MILLISECOND =
new TwoWayString2FieldBridgeAdaptor( DateBridge.DATE_MILLISECOND );
Modified: search/trunk/src/test/org/hibernate/search/test/query/Employee.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/query/Employee.java 2008-06-03
20:10:07 UTC (rev 14731)
+++ search/trunk/src/test/org/hibernate/search/test/query/Employee.java 2008-06-03
20:47:14 UTC (rev 14732)
@@ -1,6 +1,7 @@
//$Id$
package org.hibernate.search.test.query;
+import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
@@ -9,6 +10,8 @@
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;
+import org.hibernate.search.annotations.DateBridge;
+import org.hibernate.search.annotations.Resolution;
/**
* @author John Grffin
@@ -20,6 +23,18 @@
private String lastname;
private String dept;
+ @Field(store=Store.YES, index = Index.UN_TOKENIZED)
+ @DateBridge(resolution = Resolution.DAY)
+ public Date getHireDate() {
+ return hireDate;
+ }
+
+ public void setHireDate(Date hireDate) {
+ this.hireDate = hireDate;
+ }
+
+ private Date hireDate;
+
public Employee() {
}
Modified: search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java
===================================================================
---
search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java 2008-06-03
20:10:07 UTC (rev 14731)
+++
search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java 2008-06-03
20:47:14 UTC (rev 14732)
@@ -5,6 +5,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Date;
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
@@ -236,13 +237,13 @@
assertEquals( "SCORE incorrect", 1.0F, projection[4] );
assertEquals( "BOOST incorrect", 1.0F, projection[5] );
assertTrue( "DOCUMENT incorrect", projection[6] instanceof Document );
- assertEquals( "DOCUMENT size incorrect", 4, ( (Document) projection[6]
).getFields().size() );
+ assertEquals( "DOCUMENT size incorrect", 5, ( (Document) projection[6]
).getFields().size() );
assertEquals( "ID incorrect", 1001, projection[7] );
assertNotNull( "Lucene internal doc id", projection[8] );
// Change the projection order and null one
hibQuery.setProjection( FullTextQuery.DOCUMENT, FullTextQuery.THIS,
FullTextQuery.SCORE, null, FullTextQuery.ID,
- "id", "lastname", "dept", FullTextQuery.DOCUMENT_ID );
+ "id", "lastname", "dept", "hireDate",
FullTextQuery.DOCUMENT_ID );
result = hibQuery.list();
assertNotNull( result );
@@ -251,7 +252,7 @@
assertNotNull( projection );
assertTrue( "DOCUMENT incorrect", projection[0] instanceof Document );
- assertEquals( "DOCUMENT size incorrect", 4, ( (Document) projection[0]
).getFields().size() );
+ assertEquals( "DOCUMENT size incorrect", 5, ( (Document) projection[0]
).getFields().size() );
assertEquals( "THIS incorrect", projection[1], s.get( Employee.class,
(Serializable) projection[4] ) );
assertEquals( "SCORE incorrect", 1.0F, projection[2] );
assertNull( "BOOST not removed", projection[3] );
@@ -259,7 +260,8 @@
assertEquals( "id incorrect", 1001, projection[5] );
assertEquals( "last name incorrect", "Jackson", projection[6] );
assertEquals( "dept incorrect", "Accounting", projection[7] );
- assertNotNull( "Lucene internal doc id", projection[8] );
+ assertNotNull( "Date", projection[8] );
+ assertNotNull( "Lucene internal doc id", projection[9] );
//cleanup
for (Object element : s.createQuery( "from " + Employee.class.getName()
).list()) s.delete( element );
@@ -272,6 +274,7 @@
Employee e1 = new Employee( 1000, "Griffin", "ITech" );
s.save( e1 );
Employee e2 = new Employee( 1001, "Jackson", "Accounting" );
+ e2.setHireDate( new Date() );
s.save( e2 );
Employee e3 = new Employee( 1002, "Jimenez", "ITech" );
s.save( e3 );