org.apache.solr.common

## Class SolrDocument

- java.lang.Object
- - org.apache.solr.common.SolrDocumentBase<Object,SolrDocument>
  - - org.apache.solr.common.SolrDocument

- All Implemented Interfaces:
    Serializable, Iterable<Map.Entry<String,Object>>, Map<String,Object>

      public class SolrDocument
      extends SolrDocumentBase<Object,SolrDocument>
      implements Iterable<Map.Entry<String,Object>>

  A concrete representation of a document within a Solr index. Unlike a lucene Document, a SolrDocument may have an Object value matching the type defined in schema.xml For indexing documents, use the SolrInputDocument that contains extra information for document and field boosting.
  Since:
    solr 1.3
  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface java.util.Map

      `Map.Entry<K,V>`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SolrDocument()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addChildDocument(SolrDocument child)`
    `void` | `addChildDocuments(Collection<SolrDocument> children)`
    `void` | `addField(String name, Object value)` This will add a field to the document.
    `void` | `clear()` Remove all fields from the document
    `boolean` | `containsKey(Object key)`
    `boolean` | `containsValue(Object value)`
    `Set<Map.Entry<String,Object>>` | `entrySet()`
    `Object` | `get(Object key)`
    `int` | `getChildDocumentCount()`
    `List<SolrDocument>` | `getChildDocuments()` Returns the list of child documents, or null if none.
    `Collection<String>` | `getFieldNames()` Get all field names.
    `Object` | `getFieldValue(String name)` Get the value or collection of values for a given field.
    `Map<String,Object>` | `getFieldValueMap()` Expose a Map interface to the solr fields.
    `Collection<Object>` | `getFieldValues(String name)` Get a collection of values for a given field name
    `Map<String,Collection<Object>>` | `getFieldValuesMap()` Expose a Map interface to the solr field value collection.
    `Object` | `getFirstValue(String name)` returns the first value for a field
    `boolean` | `hasChildDocuments()`
    `boolean` | `isEmpty()`
    `Iterator<Map.Entry<String,Object>>` | `iterator()` Iterate of String->Object keys
    `Set<String>` | `keySet()`
    `Object` | `put(String key, Object value)`
    `void` | `putAll(Map<? extends String,? extends Object> t)`
    `Object` | `remove(Object key)`
    `boolean` | `removeFields(String name)` Remove all fields with the name
    `void` | `setField(String name, Object value)` Set a field with the given object.
    `int` | `size()`
    `String` | `toString()`
    `Collection<Object>` | `values()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach, spliterator`

    - ### Methods inherited from interface java.util.Map

      `compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll`

- - ### Constructor Detail

    - #### SolrDocument

          public SolrDocument()

  - ### Method Detail

    - #### getFieldNames

          public Collection<String> getFieldNames()

      Description copied from class: `SolrDocumentBase`
      Get all field names.
      Specified by:
        `getFieldNames` in class `SolrDocumentBase<Object,SolrDocument>`
      Returns:
        a list of field names defined in this document - this Collection is directly backed by this SolrDocument.
      See Also:
        `keySet()`

    - #### clear

          public void clear()

      Remove all fields from the document
      Specified by:
        `clear` in interface `Map<String,Object>`

    - #### removeFields

          public boolean removeFields(String name)

      Remove all fields with the name

    - #### setField

          public void setField(String name,
                               Object value)

      Set a field with the given object. If the object is an Array, it will set multiple fields with the included contents. This will replace any existing field with the given name
      Specified by:
        `setField` in class `SolrDocumentBase<Object,SolrDocument>`
      Parameters:
        `name` - name of the field to set
        `value` - value of the field

    - #### addField

          public void addField(String name,
                               Object value)

      This will add a field to the document. If fields already exist with this name it will append value to the collection. If the value is Collection, each value will be added independently. The class type of value and the name parameter should match schema.xml. schema.xml can be found in conf directory under the solr home by default.
      Specified by:
        `addField` in class `SolrDocumentBase<Object,SolrDocument>`
      Parameters:
        `name` - Name of the field, should match one of the field names defined under "fields" tag in schema.xml.
        `value` - Value of the field, should be of same class type as defined by "type" attribute of the corresponding field in schema.xml.

    - #### getFirstValue

          public Object getFirstValue(String name)

      returns the first value for a field

    - #### getFieldValue

          public Object getFieldValue(String name)

      Get the value or collection of values for a given field.
      Specified by:
        `getFieldValue` in class `SolrDocumentBase<Object,SolrDocument>`

    - #### getFieldValues

          public Collection<Object> getFieldValues(String name)

      Get a collection of values for a given field name
      Specified by:
        `getFieldValues` in class `SolrDocumentBase<Object,SolrDocument>`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### iterator

          public Iterator<Map.Entry<String,Object>> iterator()

      Iterate of String->Object keys
      Specified by:
        `iterator` in interface `Iterable<Map.Entry<String,Object>>`

    - #### getFieldValuesMap

          public Map<String,Collection<Object>> getFieldValuesMap()

      Expose a Map interface to the solr field value collection.

    - #### getFieldValueMap

          public Map<String,Object> getFieldValueMap()

      Expose a Map interface to the solr fields. This function is useful for JSTL

    - #### containsKey

          public boolean containsKey(Object key)

      Specified by:
        `containsKey` in interface `Map<String,Object>`

    - #### containsValue

          public boolean containsValue(Object value)

      Specified by:
        `containsValue` in interface `Map<String,Object>`

    - #### entrySet

          public Set<Map.Entry<String,Object>> entrySet()

      Specified by:
        `entrySet` in interface `Map<String,Object>`

    - #### get

          public Object get(Object key)

      Specified by:
        `get` in interface `Map<String,Object>`

    - #### isEmpty

          public boolean isEmpty()

      Specified by:
        `isEmpty` in interface `Map<String,Object>`

    - #### keySet

          public Set<String> keySet()

      Specified by:
        `keySet` in interface `Map<String,Object>`

    - #### put

          public Object put(String key,
                            Object value)

      Specified by:
        `put` in interface `Map<String,Object>`

    - #### putAll

          public void putAll(Map<? extends String,? extends Object> t)

      Specified by:
        `putAll` in interface `Map<String,Object>`

    - #### remove

          public Object remove(Object key)

      Specified by:
        `remove` in interface `Map<String,Object>`

    - #### size

          public int size()

      Specified by:
        `size` in interface `Map<String,Object>`

    - #### values

          public Collection<Object> values()

      Specified by:
        `values` in interface `Map<String,Object>`

    - #### addChildDocument

          public void addChildDocument(SolrDocument child)

      Specified by:
        `addChildDocument` in class `SolrDocumentBase<Object,SolrDocument>`

    - #### addChildDocuments

          public void addChildDocuments(Collection<SolrDocument> children)

      Specified by:
        `addChildDocuments` in class `SolrDocumentBase<Object,SolrDocument>`

    - #### getChildDocuments

          public List<SolrDocument> getChildDocuments()

      Returns the list of child documents, or null if none.
      Specified by:
        `getChildDocuments` in class `SolrDocumentBase<Object,SolrDocument>`

    - #### hasChildDocuments

          public boolean hasChildDocuments()

      Specified by:
        `hasChildDocuments` in class `SolrDocumentBase<Object,SolrDocument>`

    - #### getChildDocumentCount

          public int getChildDocumentCount()

      Specified by:
        `getChildDocumentCount` in class `SolrDocumentBase<Object,SolrDocument>`

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.