lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject svn commit: r1717654 - in /lucene/dev/trunk/solr: ./ solrj/src/java/org/apache/solr/client/solrj/util/ solrj/src/java/org/apache/solr/common/
Date Wed, 02 Dec 2015 15:56:17 GMT
Author: shalin
Date: Wed Dec  2 15:56:17 2015
New Revision: 1717654

URL: http://svn.apache.org/viewvc?rev=1717654&view=rev
Log:
SOLR-8339: Refactor SolrDocument and SolrInputDocument to have a common base abstract class
called SolrDocumentBase. Deprecated methods toSolrInputDocument and toSolrDocument in ClientUtils.

Added:
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrDocumentBase.java   (with
props)
Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1717654&r1=1717653&r2=1717654&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Wed Dec  2 15:56:17 2015
@@ -217,6 +217,10 @@ Other Changes
 
 * SOLR-8357: UpdateLog.RecentUpdates now implements Closeable (Alan Woodward)
 
+* SOLR-8339: Refactor SolrDocument and SolrInputDocument to have a common base abstract class
+  called SolrDocumentBase. Deprecated methods toSolrInputDocument and toSolrDocument in ClientUtils.
+  (Ishan Chattopadhyaya via shalin)
+
 ==================  5.4.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java?rev=1717654&r1=1717653&r2=1717654&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
(original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
Wed Dec  2 15:56:17 2015
@@ -66,7 +66,9 @@ public class ClientUtils
    * @param d SolrDocument to convert
    * @return a SolrInputDocument with the same fields and values as the
    *   SolrDocument.  All boosts are 1.0f
+   * @deprecated This method will be removed in Solr 6.0
    */
+  @Deprecated
   public static SolrInputDocument toSolrInputDocument( SolrDocument d )
   {
     SolrInputDocument doc = new SolrInputDocument();
@@ -79,7 +81,9 @@ public class ClientUtils
   /**
    * @param d SolrInputDocument to convert
    * @return a SolrDocument with the same fields and values as the SolrInputDocument
+   * @deprecated This method will be removed in Solr 6.0
    */
+  @Deprecated
   public static SolrDocument toSolrDocument(SolrInputDocument d) {
     SolrDocument doc = new SolrDocument();
     for (SolrInputField field : d) {

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java?rev=1717654&r1=1717653&r2=1717654&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java Wed Dec
 2 15:56:17 2015
@@ -17,7 +17,6 @@
 
 package org.apache.solr.common;
 
-import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -41,7 +40,7 @@ import org.apache.solr.common.util.Named
  *
  * @since solr 1.3
  */
-public class SolrDocument implements Map<String,Object>, Iterable<Map.Entry<String,
Object>>, Serializable
+public class SolrDocument extends SolrDocumentBase<Object, SolrDocument> implements
Iterable<Map.Entry<String, Object>>
 {
   private final Map<String,Object> _fields;
   
@@ -56,6 +55,7 @@ public class SolrDocument implements Map
    * @return a list of field names defined in this document - this Collection is directly
backed by this SolrDocument.
    * @see #keySet
    */
+  @Override
   public Collection<String> getFieldNames() {
     return this.keySet();
   }
@@ -124,6 +124,7 @@ public class SolrDocument implements Map
    * @param value Value of the field, should be of same class type as defined by "type" attribute
of the corresponding field in schema.xml. 
    */
   @SuppressWarnings("unchecked")
+  @Override
   public void addField(String name, Object value) 
   { 
     Object existing = _fields.get(name);
@@ -186,6 +187,7 @@ public class SolrDocument implements Map
   /**
    * Get the value or collection of values for a given field.  
    */
+  @Override
   public Object getFieldValue(String name) {
     return _fields.get( name );
   }
@@ -194,6 +196,7 @@ public class SolrDocument implements Map
    * Get a collection of values for a given field name
    */
   @SuppressWarnings("unchecked")
+  @Override
   public Collection<Object> getFieldValues(String name) {
     Object v = _fields.get( name );
     if( v instanceof Collection ) {
@@ -366,7 +369,8 @@ public class SolrDocument implements Map
   public Collection<Object> values() {
     return _fields.values();
   }
-  
+
+  @Override
   public void addChildDocument(SolrDocument child) {
     if (_childDocuments == null) {
       _childDocuments = new ArrayList<>();
@@ -374,22 +378,26 @@ public class SolrDocument implements Map
      _childDocuments.add(child);
    }
    
-   public void addChildDocuments(Collection<SolrDocument> childs) {
-     for (SolrDocument child : childs) {
+  @Override
+   public void addChildDocuments(Collection<SolrDocument> children) {
+     for (SolrDocument child : children) {
        addChildDocument(child);
      }
    }
 
    /** Returns the list of child documents, or null if none. */
+   @Override
    public List<SolrDocument> getChildDocuments() {
      return _childDocuments;
    }
    
+   @Override
    public boolean hasChildDocuments() {
      boolean isEmpty = (_childDocuments == null || _childDocuments.isEmpty());
      return !isEmpty;
    }
 
+  @Override
   public int getChildDocumentCount() {
     return _childDocuments.size();
   }

Added: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrDocumentBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrDocumentBase.java?rev=1717654&view=auto
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrDocumentBase.java (added)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrDocumentBase.java Wed
Dec  2 15:56:17 2015
@@ -0,0 +1,64 @@
+package org.apache.solr.common;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public abstract class SolrDocumentBase<T, K> implements Map<String, T>, Serializable
{
+
+  /** Get all field names.
+  */
+  public abstract Collection<String> getFieldNames();
+
+  /** Set a field with implied null value for boost.
+   * @param name name of the field to set
+   * @param value value of the field
+   */
+  public abstract void setField(String name, Object value);
+
+  /** 
+   * Add a field to the document.
+   * @param name Name of the field, should match one of the field names defined under "fields"
tag in schema.xml.
+   * @param value Value of the field, should be of same class type as defined by "type" attribute
of the corresponding field in schema.xml. 
+   */
+  public abstract void addField(String name, Object value); 
+
+  /**
+   * Get the first value or collection of values for a given field.
+   */
+  public abstract Object getFieldValue(String name);
+
+  /**
+   * Get a collection of values for a given field name
+   */
+  public abstract Collection getFieldValues(String name);
+
+  public abstract void addChildDocument(K child);
+
+  public abstract void addChildDocuments(Collection<K> children);
+
+  public abstract List<K> getChildDocuments();
+
+  public abstract boolean hasChildDocuments();
+
+  public abstract int getChildDocumentCount();
+
+}

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java?rev=1717654&r1=1717653&r2=1717654&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java Wed
Dec  2 15:56:17 2015
@@ -17,10 +17,8 @@
 
 package org.apache.solr.common;
 
-import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -35,7 +33,7 @@ import java.util.Set;
  *
  * @since solr 1.3
  */
-public class SolrInputDocument implements Map<String,SolrInputField>, Iterable<SolrInputField>,
Serializable
+public class SolrInputDocument extends SolrDocumentBase<SolrInputField, SolrInputDocument>
implements Iterable<SolrInputField>
 {
   private final Map<String,SolrInputField> _fields;
   private float _documentBoost = 1.0f;
@@ -85,6 +83,7 @@ public class SolrInputDocument implement
    * @param name name of the field to fetch
    * @return first value of the field or null if not present
    */
+  @Override
   public Object getFieldValue(String name) 
   {
     SolrInputField field = getField(name);
@@ -98,6 +97,7 @@ public class SolrInputDocument implement
    * @param name name of the field to fetch
    * @return value of the field or null if not set
    */
+  @Override
   public Collection<Object> getFieldValues(String name) 
   {
     SolrInputField field = getField(name);
@@ -111,6 +111,7 @@ public class SolrInputDocument implement
    * 
    * @return Set of all field names.
    */
+  @Override
   public Collection<String> getFieldNames() 
   {
     return _fields.keySet();
@@ -276,6 +277,7 @@ public class SolrInputDocument implement
     return _fields.values();
   }
 
+  @Override
   public void addChildDocument(SolrInputDocument child) {
    if (_childDocuments == null) {
      _childDocuments = new ArrayList<>();
@@ -283,8 +285,8 @@ public class SolrInputDocument implement
     _childDocuments.add(child);
   }
   
-  public void addChildDocuments(Collection<SolrInputDocument> childs) {
-    for (SolrInputDocument child : childs) {
+  public void addChildDocuments(Collection<SolrInputDocument> children) {
+    for (SolrInputDocument child : children) {
       addChildDocument(child);
     }
   }
@@ -298,4 +300,9 @@ public class SolrInputDocument implement
     boolean isEmpty = (_childDocuments == null || _childDocuments.isEmpty());
     return !isEmpty;
   }
+
+  @Override
+  public int getChildDocumentCount() {
+    return hasChildDocuments() ? _childDocuments.size(): 0;
+  }
 }



Mime
View raw message