[hibernate-commits] Hibernate SVN: r14924 - in search/trunk: src/java/org/hibernate/search/bridge and 2 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Jul 11 12:40:36 EDT 2008
Author: hardy.ferentschik
Date: 2008-07-11 12:40:35 -0400 (Fri, 11 Jul 2008)
New Revision: 14924
Modified:
search/trunk/doc/reference/en/modules/mapping.xml
search/trunk/src/java/org/hibernate/search/bridge/FieldBridge.java
search/trunk/src/java/org/hibernate/search/bridge/LuceneOptions.java
search/trunk/src/java/org/hibernate/search/bridge/String2FieldBridgeAdaptor.java
search/trunk/src/test/org/hibernate/search/test/bridge/CatDeptsFieldsClassBridge.java
search/trunk/src/test/org/hibernate/search/test/bridge/CatFieldsClassBridge.java
search/trunk/src/test/org/hibernate/search/test/bridge/DateSplitBridge.java
search/trunk/src/test/org/hibernate/search/test/bridge/EquipmentType.java
search/trunk/src/test/org/hibernate/search/test/bridge/TruncateFieldBridge.java
search/trunk/src/test/org/hibernate/search/test/id/PersonPKBridge.java
Log:
HSEARCH-156:
- Updated the documentation
- Added getters to LuceneOptions
Modified: search/trunk/doc/reference/en/modules/mapping.xml
===================================================================
--- search/trunk/doc/reference/en/modules/mapping.xml 2008-07-11 15:22:42 UTC (rev 14923)
+++ search/trunk/doc/reference/en/modules/mapping.xml 2008-07-11 16:40:35 UTC (rev 14924)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
+<chapter id="search-mapping" revision="3">
+ <!-- $Id$ -->
-<chapter id="search-mapping" revision="3">
- <!-- $Id$ -->
<title>Mapping entities to the index structure</title>
<para>All the metadata information needed to index entities is described
@@ -790,43 +790,48 @@
document fields</para>
<programlisting>/**
- * Store the date in 3 different field year, month, day
- * to ease Range Query per year, month or day
- * (eg get all the elements of december for the last 5 years)
- *
+ * Store the date in 3 different fields - year, month, day - to ease Range Query per
+ * year, month or day (eg get all the elements of December for the last 5 years).
+ *
* @author Emmanuel Bernard
*/
public class DateSplitBridge implements FieldBridge {
private final static TimeZone GMT = TimeZone.getTimeZone("GMT");
- <emphasis role="bold">public void set(String name, Object value, Document document, Field.Store
- store, Field.Index index, Float boost) {
- </emphasis>
+ <emphasis role="bold">public void set(String name, Object value, Document document, LuceneOptions luceneOptions)</emphasis> {
Date date = (Date) value;
- Calendar cal = GregorianCalendar.getInstance( GMT );
- cal.setTime( date );
- int year = cal.get( Calendar.YEAR );
- int month = cal.get( Calendar.MONTH ) + 1;
- int day = cal.get( Calendar.DAY_OF_MONTH );
- //set year
- Field field = new Field( name + ".year", String.valueOf(year), store, index );
- if ( boost != null ) field.setBoost( boost );
- document.add( field );
- //set month and pad it if needed
- field = new Field( name + ".month", month < 10 ? "0" : "" + String.valueOf(month), store, index);
- if ( boost != null ) field.setBoost( boost );
- document.add( field );
- //set day and pad it if needed
- field = new Field( name + ".day", day < 10 ? "0" : "" + String.valueOf(day), store, index );
- if ( boost != null ) field.setBoost( boost );
- document.add( field );
+ Calendar cal = GregorianCalendar.getInstance(GMT);
+ cal.setTime(date);
+ int year = cal.get(Calendar.YEAR);
+ int month = cal.get(Calendar.MONTH) + 1;
+ int day = cal.get(Calendar.DAY_OF_MONTH);
+
+ // set year
+ Field field = new Field(name + ".year", String.valueOf(year),
+ luceneOptions.getStore(), luceneOptions.getIndex(),
+ luceneOptions.getTermVector());
+ field.setBoost(luceneOptions.getBoost());
+ document.add(field);
+
+ // set month and pad it if needed
+ field = new Field(name + ".month", month < 10 ? "0" : ""
+ + String.valueOf(month), luceneOptions.getStore(),
+ luceneOptions.getIndex(), luceneOptions.getTermVector());
+ field.setBoost(luceneOptions.getBoost());
+ document.add(field);
+
+ // set day and pad it if needed
+ field = new Field(name + ".day", day < 10 ? "0" : ""
+ + String.valueOf(day), luceneOptions.getStore(),
+ luceneOptions.getIndex(), luceneOptions.getTermVector());
+ field.setBoost(luceneOptions.getBoost());
+ document.add(field);
}
}
-
//property
<emphasis role="bold">@FieldBridge(impl = DateSplitBridge.class)</emphasis>
-private Integer length; </programlisting>
+private Date date; </programlisting>
<para></para>
</section>
@@ -861,18 +866,15 @@
...
}
+
public class CatFieldsClassBridge implements FieldBridge, ParameterizedBridge {
-
private String sepChar;
public void setParameterValues(Map parameters) {
this.sepChar = (String) parameters.get( "sepChar" );
}
- public void set(String name,
- Object value, //the department instance (entity) in this case
- Document document, //the Lucene document
- Field.Store store, Field.Index index, Float boost) {
+ <emphasis role="bold">public void set(String name, Object value, Document document, LuceneOptions luceneOptions)</emphasis> {
// In this particular class the name of the new field was passed
// from the name field of the ClassBridge Annotation. This is not
// a requirement. It just works that way in this instance. The
@@ -887,10 +889,10 @@
fieldValue2 = "";
}
String fieldValue = fieldValue1 + sepChar + fieldValue2;
- Field field = new Field( name, fieldValue, store, index );
- if ( boost != null ) field.setBoost( boost );
+ Field field = new Field( name, fieldValue, luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector() );
+ field.setBoost( luceneOptions.getBoost() );
document.add( field );
- }
+ }
}</programlisting>
<para>In this example, the particular
Modified: search/trunk/src/java/org/hibernate/search/bridge/FieldBridge.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/bridge/FieldBridge.java 2008-07-11 15:22:42 UTC (rev 14923)
+++ search/trunk/src/java/org/hibernate/search/bridge/FieldBridge.java 2008-07-11 16:40:35 UTC (rev 14924)
@@ -2,7 +2,6 @@
package org.hibernate.search.bridge;
import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
/**
* Link between a java property and a Lucene Document
@@ -17,7 +16,8 @@
* A common implementation is to add a Field <code>name</code> to the given document following
* the parameters (<code>store</code>, <code>index</code>, <code>boost</code>) if the
* <code>value</code> is not null
- * @param parameterObject TODO
+ * @param luceneOptions Contains the parameters used for adding <code>value</code> to
+ * the Lucene <code>document</code>.
*/
- void set(String name, Object value, Document document, LuceneOptions parameterObject);
+ void set(String name, Object value, Document document, LuceneOptions luceneOptions);
}
Modified: search/trunk/src/java/org/hibernate/search/bridge/LuceneOptions.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/bridge/LuceneOptions.java 2008-07-11 15:22:42 UTC (rev 14923)
+++ search/trunk/src/java/org/hibernate/search/bridge/LuceneOptions.java 2008-07-11 16:40:35 UTC (rev 14924)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
package org.hibernate.search.bridge;
import org.apache.lucene.document.Field.Index;
@@ -11,10 +11,10 @@
* @author Hardy Ferentschik
*/
public class LuceneOptions {
- public Store store;
- public Index index;
- public TermVector termVector;
- public Float boost;
+ private final Store store;
+ private final Index index;
+ private final TermVector termVector;
+ private final Float boost;
public LuceneOptions(Store store, Index index, TermVector termVector, Float boost) {
this.store = store;
@@ -22,4 +22,28 @@
this.termVector = termVector;
this.boost = boost;
}
+
+ public Store getStore() {
+ return store;
+ }
+
+ public Index getIndex() {
+ return index;
+ }
+
+ public TermVector getTermVector() {
+ return termVector;
+ }
+
+ /**
+ * @return the boost value. If <code>boost == null</code>, the default boost value
+ * 1.0 is returned.
+ */
+ public Float getBoost() {
+ if ( boost != null ) {
+ return boost;
+ } else {
+ return 1.0f;
+ }
+ }
}
\ No newline at end of file
Modified: search/trunk/src/java/org/hibernate/search/bridge/String2FieldBridgeAdaptor.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/bridge/String2FieldBridgeAdaptor.java 2008-07-11 15:22:42 UTC (rev 14923)
+++ search/trunk/src/java/org/hibernate/search/bridge/String2FieldBridgeAdaptor.java 2008-07-11 16:40:35 UTC (rev 14924)
@@ -17,13 +17,13 @@
this.stringBridge = stringBridge;
}
- public void set(String name, Object value, Document document, LuceneOptions parameterObject) {
+ public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
String indexedString = stringBridge.objectToString( value );
//Do not add fields on empty strings, seems a sensible default in most situations
//TODO if Store, probably also save empty ones
if ( StringHelper.isNotEmpty( indexedString ) ) {
- Field field = new Field( name, indexedString, parameterObject.store, parameterObject.index, parameterObject.termVector );
- if ( parameterObject.boost != null ) field.setBoost( parameterObject.boost );
+ Field field = new Field( name, indexedString, luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector() );
+ field.setBoost( luceneOptions.getBoost() );
document.add( field );
}
}
Modified: search/trunk/src/test/org/hibernate/search/test/bridge/CatDeptsFieldsClassBridge.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/bridge/CatDeptsFieldsClassBridge.java 2008-07-11 15:22:42 UTC (rev 14923)
+++ search/trunk/src/test/org/hibernate/search/test/bridge/CatDeptsFieldsClassBridge.java 2008-07-11 16:40:35 UTC (rev 14924)
@@ -15,11 +15,12 @@
private String sepChar;
+ @SuppressWarnings("unchecked")
public void setParameterValues(Map parameters) {
this.sepChar = (String) parameters.get( "sepChar" );
}
- public void set(String name, Object value, Document document, LuceneOptions parameterObject) {
+ public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
// In this particular class the name of the new field was passed
// from the name field of the ClassBridge Annotation. This is not
// a requirement. It just works that way in this instance. The
@@ -34,8 +35,8 @@
fieldValue2 = "";
}
String fieldValue = fieldValue1 + sepChar + fieldValue2;
- Field field = new Field( name, fieldValue, parameterObject.store, parameterObject.index, parameterObject.termVector );
- if ( parameterObject.boost != null ) field.setBoost( parameterObject.boost );
+ Field field = new Field( name, fieldValue, luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector() );
+ field.setBoost( luceneOptions.getBoost() );
document.add( field );
}
}
Modified: search/trunk/src/test/org/hibernate/search/test/bridge/CatFieldsClassBridge.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/bridge/CatFieldsClassBridge.java 2008-07-11 15:22:42 UTC (rev 14923)
+++ search/trunk/src/test/org/hibernate/search/test/bridge/CatFieldsClassBridge.java 2008-07-11 16:40:35 UTC (rev 14924)
@@ -20,7 +20,7 @@
this.sepChar = (String) parameters.get( "sepChar" );
}
- public void set(String name, Object value, Document document, LuceneOptions parameterObject) {
+ public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
// In this particular class the name of the new field was passed
// from the name field of the ClassBridge Annotation. This is not
// a requirement. It just works that way in this instance. The
@@ -35,8 +35,8 @@
fieldValue2 = "";
}
String fieldValue = fieldValue1 + sepChar + fieldValue2;
- Field field = new Field( name, fieldValue, parameterObject.store, parameterObject.index, parameterObject.termVector );
- if ( parameterObject.boost != null ) field.setBoost( parameterObject.boost );
+ Field field = new Field( name, fieldValue, luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector() );
+ field.setBoost( luceneOptions.getBoost() );
document.add( field );
}
}
Modified: search/trunk/src/test/org/hibernate/search/test/bridge/DateSplitBridge.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/bridge/DateSplitBridge.java 2008-07-11 15:22:42 UTC (rev 14923)
+++ search/trunk/src/test/org/hibernate/search/test/bridge/DateSplitBridge.java 2008-07-11 16:40:35 UTC (rev 14924)
@@ -12,33 +12,41 @@
import org.hibernate.search.bridge.LuceneOptions;
/**
- * Store the date in 3 different field year, month, day
- * to ease Range Query per year, month or day
- * (eg get all the elements of december for the last 5 years)
- *
+ * Store the date in 3 different fields - year, month, day - to ease Range Query per
+ * year, month or day (eg get all the elements of December for the last 5 years).
+ *
* @author Emmanuel Bernard
*/
public class DateSplitBridge implements FieldBridge {
- private final static TimeZone GMT = TimeZone.getTimeZone( "GMT" );
+ private final static TimeZone GMT = TimeZone.getTimeZone("GMT");
- public void set(String name, Object value, Document document, LuceneOptions parameterObject) {
+ public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
Date date = (Date) value;
- Calendar cal = GregorianCalendar.getInstance( GMT );
- cal.setTime( date );
- int year = cal.get( Calendar.YEAR );
- int month = cal.get( Calendar.MONTH ) + 1;
- int day = cal.get( Calendar.DAY_OF_MONTH );
- //set year
- Field field = new Field( name + ".year", String.valueOf( year ), parameterObject.store, parameterObject.index, parameterObject.termVector );
- if ( parameterObject.boost != null ) field.setBoost( parameterObject.boost );
- document.add( field );
- //set month and pad it if needed
- field = new Field( name + ".month", month < 10 ? "0" : "" + String.valueOf( month ), parameterObject.store, parameterObject.index, parameterObject.termVector );
- if ( parameterObject.boost != null ) field.setBoost( parameterObject.boost );
- document.add( field );
- //set day and pad it if needed
- field = new Field( name + ".day", day < 10 ? "0" : "" + String.valueOf( day ), parameterObject.store, parameterObject.index, parameterObject.termVector );
- if ( parameterObject.boost != null ) field.setBoost( parameterObject.boost );
- document.add( field );
+ Calendar cal = GregorianCalendar.getInstance(GMT);
+ cal.setTime(date);
+ int year = cal.get(Calendar.YEAR);
+ int month = cal.get(Calendar.MONTH) + 1;
+ int day = cal.get(Calendar.DAY_OF_MONTH);
+
+ // set year
+ Field field = new Field(name + ".year", String.valueOf(year),
+ luceneOptions.getStore(), luceneOptions.getIndex(),
+ luceneOptions.getTermVector());
+ field.setBoost(luceneOptions.getBoost());
+ document.add(field);
+
+ // set month and pad it if needed
+ field = new Field(name + ".month", month < 10 ? "0" : ""
+ + String.valueOf(month), luceneOptions.getStore(),
+ luceneOptions.getIndex(), luceneOptions.getTermVector());
+ field.setBoost(luceneOptions.getBoost());
+ document.add(field);
+
+ // set day and pad it if needed
+ field = new Field(name + ".day", day < 10 ? "0" : ""
+ + String.valueOf(day), luceneOptions.getStore(),
+ luceneOptions.getIndex(), luceneOptions.getTermVector());
+ field.setBoost(luceneOptions.getBoost());
+ document.add(field);
}
}
Modified: search/trunk/src/test/org/hibernate/search/test/bridge/EquipmentType.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/bridge/EquipmentType.java 2008-07-11 15:22:42 UTC (rev 14923)
+++ search/trunk/src/test/org/hibernate/search/test/bridge/EquipmentType.java 2008-07-11 16:40:35 UTC (rev 14924)
@@ -11,6 +11,7 @@
/**
* @author John Griffin
*/
+ at SuppressWarnings("unchecked")
public class EquipmentType implements FieldBridge, ParameterizedBridge {
private Map equips;
@@ -19,7 +20,7 @@
this.equips = parameters;
}
- public void set(String name, Object value, Document document, LuceneOptions parameterObject) {
+ public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
// In this particular class the name of the new field was passed
// from the name field of the ClassBridge Annotation. This is not
// a requirement. It just works that way in this instance. The
@@ -33,8 +34,8 @@
}
else {
String fieldValue = (String) equips.get( fieldValue1 );
- field = new Field( name, fieldValue, parameterObject.store, parameterObject.index, parameterObject.termVector );
- if ( parameterObject.boost != null ) field.setBoost( parameterObject.boost );
+ field = new Field( name, fieldValue, luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector() );
+ field.setBoost( luceneOptions.getBoost() );
}
document.add( field );
}
Modified: search/trunk/src/test/org/hibernate/search/test/bridge/TruncateFieldBridge.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/bridge/TruncateFieldBridge.java 2008-07-11 15:22:42 UTC (rev 14923)
+++ search/trunk/src/test/org/hibernate/search/test/bridge/TruncateFieldBridge.java 2008-07-11 16:40:35 UTC (rev 14924)
@@ -16,12 +16,14 @@
return field.stringValue();
}
- public void set(String name, Object value, Document document, LuceneOptions parameterObject) {
+ public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
String indexedString = (String) value;
//Do not add fields on empty strings, seems a sensible default in most situations
if ( StringHelper.isNotEmpty( indexedString ) ) {
- Field field = new Field( name, indexedString.substring( 0, indexedString.length() / 2 ), parameterObject.store, parameterObject.index, parameterObject.termVector );
- if ( parameterObject.boost != null ) field.setBoost( parameterObject.boost );
+ Field field = new Field(name, indexedString.substring(0,
+ indexedString.length() / 2), luceneOptions.getStore(),
+ luceneOptions.getIndex(), luceneOptions.getTermVector());
+ field.setBoost( luceneOptions.getBoost() );
document.add( field );
}
}
Modified: search/trunk/src/test/org/hibernate/search/test/id/PersonPKBridge.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/id/PersonPKBridge.java 2008-07-11 15:22:42 UTC (rev 14923)
+++ search/trunk/src/test/org/hibernate/search/test/id/PersonPKBridge.java 2008-07-11 16:40:35 UTC (rev 14924)
@@ -1,4 +1,4 @@
-//$
+// $Id:$
package org.hibernate.search.test.id;
import org.apache.lucene.document.Document;
@@ -27,20 +27,21 @@
return sb.toString();
}
- public void set(String name, Object value, Document document, LuceneOptions parameterObject) {
+ public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
PersonPK id = (PersonPK) value;
//store each property in a unique field
- Field field = new Field( name + ".firstName", id.getFirstName(), parameterObject.store, parameterObject.index, parameterObject.termVector );
- if ( parameterObject.boost != null ) field.setBoost( parameterObject.boost );
+ Field field = new Field( name + ".firstName", id.getFirstName(), luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector() );
+ field.setBoost( luceneOptions.getBoost() );
document.add( field );
- field = new Field( name + ".lastName", id.getLastName(), parameterObject.store, parameterObject.index, parameterObject.termVector );
- if ( parameterObject.boost != null ) field.setBoost( parameterObject.boost );
+
+ field = new Field( name + ".lastName", id.getLastName(), luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector() );
+ field.setBoost( luceneOptions.getBoost() );
document.add( field );
//store the unique string representation in the named field
- field = new Field( name, objectToString( id ), parameterObject.store, parameterObject.index, parameterObject.termVector );
- if ( parameterObject.boost != null ) field.setBoost( parameterObject.boost );
+ field = new Field( name, objectToString( id ), luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector() );
+ field.setBoost( luceneOptions.getBoost() );
document.add( field );
}
}
More information about the hibernate-commits
mailing list