mirror of https://github.com/apache/lucene.git
SOLR-928: SolrDocument and SolrInputDocument now implement the Map<String,?>
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@728104 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6853173298
commit
f822432153
|
@ -122,6 +122,8 @@ New Features
|
|||
option, as well as a list of protected terms.
|
||||
(Dan Rosher via hossman)
|
||||
|
||||
25. SOLR-928: SolrDocument and SolrInputDocument now implement the Map<String,?>
|
||||
interface. This should make plugging into other standard tools easier. (ryan)
|
||||
|
||||
|
||||
Optimizations
|
||||
|
|
|
@ -21,11 +21,10 @@ import java.io.Serializable;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -39,13 +38,13 @@ import java.util.Map.Entry;
|
|||
* @version $Id$
|
||||
* @since solr 1.3
|
||||
*/
|
||||
public class SolrDocument implements Serializable, Iterable<Map.Entry<String, Object>>
|
||||
public class SolrDocument implements Map<String,Object>, Iterable<Map.Entry<String, Object>>, Serializable
|
||||
{
|
||||
private Map<String,Object> _fields = null;
|
||||
private final Map<String,Object> _fields;
|
||||
|
||||
public SolrDocument()
|
||||
{
|
||||
_fields = new HashMap<String,Object>();
|
||||
_fields = new LinkedHashMap<String,Object>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -250,4 +249,63 @@ public class SolrDocument implements Serializable, Iterable<Map.Entry<String, Ob
|
|||
public Collection<Object> remove(Object key) {throw new UnsupportedOperationException();}
|
||||
};
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
// MAP interface
|
||||
//---------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
return _fields.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
return _fields.containsValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Entry<String, Object>> entrySet() {
|
||||
return _fields.entrySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(Object key) {
|
||||
return _fields.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return _fields.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> keySet() {
|
||||
return _fields.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object put(String key, Object value) {
|
||||
return _fields.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map<? extends String, ? extends Object> t) {
|
||||
_fields.putAll( t );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object remove(Object key) {
|
||||
return _fields.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return _fields.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Object> values() {
|
||||
return _fields.values();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
package org.apache.solr.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Represent the field and boost information needed to construct and index
|
||||
|
@ -32,13 +32,12 @@ import java.util.Collection;
|
|||
* @version $Id$
|
||||
* @since solr 1.3
|
||||
*/
|
||||
public class SolrInputDocument implements Iterable<SolrInputField>, Serializable
|
||||
public class SolrInputDocument implements Map<String,SolrInputField>, Iterable<SolrInputField>, Serializable
|
||||
{
|
||||
private final Map<String,SolrInputField> _fields;
|
||||
private float _documentBoost = 1.0f;
|
||||
|
||||
public SolrInputDocument()
|
||||
{
|
||||
public SolrInputDocument() {
|
||||
_fields = new LinkedHashMap<String,SolrInputField>();
|
||||
}
|
||||
|
||||
|
@ -173,4 +172,64 @@ public class SolrInputDocument implements Iterable<SolrInputField>, Serializable
|
|||
{
|
||||
return "SolrInputDocument["+_fields+"]";
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------
|
||||
// MAP interface
|
||||
//---------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
return _fields.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
return _fields.containsValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Entry<String, SolrInputField>> entrySet() {
|
||||
return _fields.entrySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolrInputField get(Object key) {
|
||||
return _fields.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return _fields.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> keySet() {
|
||||
return _fields.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolrInputField put(String key, SolrInputField value) {
|
||||
return _fields.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map<? extends String, ? extends SolrInputField> t) {
|
||||
_fields.putAll( t );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolrInputField remove(Object key) {
|
||||
return _fields.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return _fields.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SolrInputField> values() {
|
||||
return _fields.values();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.solr.common.SolrDocument;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
|
@ -175,6 +176,17 @@ public class SolrDocumentTest extends TestCase
|
|||
}
|
||||
assertEquals( (3*5), doc.getField("f").getValueCount() );
|
||||
}
|
||||
|
||||
public void testMapInterface()
|
||||
{
|
||||
SolrDocument doc = new SolrDocument();
|
||||
assertTrue( doc instanceof Map );
|
||||
assertTrue( Map.class.isAssignableFrom( SolrDocument.class ) );
|
||||
|
||||
SolrInputDocument indoc = new SolrInputDocument();
|
||||
assertTrue( indoc instanceof Map );
|
||||
assertTrue( Map.class.isAssignableFrom( indoc.getClass() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue