Java Mailing List Archive

http://www.gg3721.com/

Home » Hibernate Commits List »

[hibernate-commits] Hibernate SVN: r14924 - in search/trunk:
 src/java/org/hibernate/search/bridge and 2 other directories.

hibernate-commits

2008-07-11


Author LoginPost Reply
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)
@@(protected) @@
<?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
@@(protected) @@
     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 &lt; 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 &lt; 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 &lt; 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 &lt; 10 ? "0" : ""
+        + String.valueOf(day), luceneOptions.getStore(),
+        luceneOptions.getIndex(), luceneOptions.getTermVector());
+     field.setBoost(luceneOptions.getBoost());
+     document.add(field);
  }
}

-
//property
<emphasis role="bold">@(protected)>
-private Integer length;           </programlisting>
+private Date date;           </programlisting>

     <para></para>
    </section>
@@(protected) @@
  ...
}

+
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
@@(protected) @@
        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)
@@(protected) @@
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
@@(protected) @@
  * 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)
@@(protected) @@
-// $Id:$
+// $Id$
package org.hibernate.search.bridge;

import org.apache.lucene.document.Field.Index;
@@(protected) @@
* @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;
@@(protected) @@
   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)
@@(protected) @@
   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)
@@(protected) @@

 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
@@(protected) @@
     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)
@@(protected) @@
   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
@@(protected) @@
     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)
@@(protected) @@
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)
@@(protected) @@
/**
* @author John Griffin
*/
+@(protected)")
public class EquipmentType implements FieldBridge, ParameterizedBridge {
 private Map equips;

@@(protected) @@
   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
@@(protected) @@
   }
   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)
@@(protected) @@
   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)
@@(protected) @@
-//$
+// $Id:$
package org.hibernate.search.test.id;

import org.apache.lucene.document.Document;
@@(protected) @@
   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 );
 }
}

_______________________________________________
hibernate-commits mailing list
hibernate-commits@(protected)
https://lists.jboss.org/mailman/listinfo/hibernate-commits
©2008 gg3721.com - Jax Systems, LLC, U.S.A.