You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ry...@apache.org on 2007/07/02 17:43:53 UTC

svn commit: r552514 - /lucene/solr/trunk/src/java/org/apache/solr/common/SolrInputDocument.java

Author: ryan
Date: Mon Jul  2 08:43:50 2007
New Revision: 552514

URL: http://svn.apache.org/viewvc?view=rev&rev=552514
Log:
SOLR-280 -- adding wrapper functions for API compatibility.  thanks Will

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/common/SolrInputDocument.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/common/SolrInputDocument.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/common/SolrInputDocument.java?view=diff&rev=552514&r1=552513&r2=552514
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/common/SolrInputDocument.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/common/SolrInputDocument.java Mon Jul  2 08:43:50 2007
@@ -21,6 +21,8 @@
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Map;
+import java.util.Set;
+import java.util.Collection;
 
 /**
  * Represent the field and boost information needed to construct and index
@@ -74,6 +76,65 @@
     return false;
   }
   
+  /** 
+   * Add a field with implied null value for boost.
+   * 
+   * @see addField(String, Object, Float)
+   * @param name name of the field to add
+   * @param value value of the field
+   */
+  public void addField(String name, Object value) 
+  {
+    addField(name, value, null);
+  }
+  
+  /** Get the first value for a field.
+   * 
+   * @param name name of the field to fetch
+   * @return first value of the field or null if not present
+   */
+  public Object getFieldValue(String name) 
+  {
+    SolrInputField field = getField(name);
+    Object o = null;
+    if (field!=null) o = field.getFirstValue();
+    return o;
+  }
+  
+  /** Get all the values for a field.
+   * 
+   * @param name name of the field to fetch
+   * @return value of the field or null if not set
+   */
+  public Collection<Object> getFieldValues(String name) 
+  {
+    SolrInputField field = getField(name);
+    if (field!=null) {
+      return field.getValues();
+    }
+    return null;
+  } 
+  
+  /** Get all field names.
+   * 
+   * @return Set of all field names.
+   */
+  public Collection<String> getFieldNames() 
+  {
+    return _fields.keySet();
+  }
+  
+  /** Set a field with implied null value for boost.
+   * 
+   * @see setField(String, Object, Float)
+   * @param name name of the field to set
+   * @param value value of the field
+   */
+  public void setField(String name, Object value) 
+  {
+    setField(name, value, null);
+  }
+  
   public void setField(String name, Object value, Float boost ) 
   {
     SolrInputField field = new SolrInputField( name );
@@ -101,11 +162,14 @@
     }
   }
 
+  /**
+   * Remove a field
+   * 
+   * @param the field name
+   * @return true if a field was removed
+   */
   public boolean removeField(String name) {
-    if( name != null ) {
-      return _fields.remove( name ) != null;
-    }
-    return false;
+    return _fields.remove( name ) != null;
   }
   
   /**