mirror of https://github.com/apache/lucene.git
SOLR-8339: Refactor SolrDocument and SolrInputDocument to have a common base abstract class called SolrDocumentBase. Deprecated methods toSolrInputDocument and toSolrDocument in ClientUtils.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1717654 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
30f941068a
commit
0618b18f7b
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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.NamedList;
|
|||
*
|
||||
* @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<String,Object>, Iterable<Map.Entry<Stri
|
|||
* @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<String,Object>, Iterable<Map.Entry<Stri
|
|||
* @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<String,Object>, Iterable<Map.Entry<Stri
|
|||
/**
|
||||
* 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<String,Object>, Iterable<Map.Entry<Stri
|
|||
* 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<String,Object>, Iterable<Map.Entry<Stri
|
|||
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<String,Object>, Iterable<Map.Entry<Stri
|
|||
_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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -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 implements Map<String,SolrInputField>, Iterable<S
|
|||
* @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 implements Map<String,SolrInputField>, Iterable<S
|
|||
* @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 implements Map<String,SolrInputField>, Iterable<S
|
|||
*
|
||||
* @return Set of all field names.
|
||||
*/
|
||||
@Override
|
||||
public Collection<String> getFieldNames()
|
||||
{
|
||||
return _fields.keySet();
|
||||
|
@ -276,6 +277,7 @@ public class SolrInputDocument implements Map<String,SolrInputField>, Iterable<S
|
|||
return _fields.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChildDocument(SolrInputDocument child) {
|
||||
if (_childDocuments == null) {
|
||||
_childDocuments = new ArrayList<>();
|
||||
|
@ -283,8 +285,8 @@ public class SolrInputDocument implements Map<String,SolrInputField>, Iterable<S
|
|||
_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 implements Map<String,SolrInputField>, Iterable<S
|
|||
boolean isEmpty = (_childDocuments == null || _childDocuments.isEmpty());
|
||||
return !isEmpty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildDocumentCount() {
|
||||
return hasChildDocuments() ? _childDocuments.size(): 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue