Class SearchDocument

  • All Implemented Interfaces:
    java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<SearchField>

    public class SearchDocument
    extends java.lang.Object
    implements java.lang.Iterable<SearchField>, java.lang.Cloneable, java.io.Externalizable
    A document returned from a search.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      SearchDocument()
      Construct a new SearchDocument.
      SearchDocument​(java.lang.String id)
      Construct a new SearchDocument with an id.
    • Constructor Detail

      • SearchDocument

        public SearchDocument()
        Construct a new SearchDocument.
      • SearchDocument

        public SearchDocument​(java.lang.String id)
        Construct a new SearchDocument with an id.
    • Method Detail

      • getId

        public java.lang.String getId()
        The unique document id.

        NOTE: the document id may not be populated for SearchDocuments if not requested. If not populated, an empty string will be returned.

      • getZone

        public java.lang.String getZone()
        Get the zone this document is in

        NOTE: the zone name may not be populated for SearchDocuments if not requested. If not populated, null will be returned.

      • setFeatures

        public void setFeatures​(RelevancyFeatureVector value)
        Set the feature vector for relevancy components.
      • getScore

        public float getScore()
        Get the document's score.

        NOTE: May return 0.0f if no score was computed, or if score was requested with custom field name.

        Throws:
        java.lang.IllegalArgumentException - if field named FieldNames.SCORE contains non-numeric values.
      • size

        public int size()
        Get the number of fields in this document.
      • getFieldNames

        public java.lang.Iterable<java.lang.String> getFieldNames()
        Return an Iterable for iterating over all unique field names.
      • iterator

        public java.util.Iterator<SearchField> iterator()
        Get an iterator for iterating over all fields.
        Specified by:
        iterator in interface java.lang.Iterable<SearchField>
      • forEach

        public void forEach​(java.util.function.Consumer<? super SearchField> consumer)
        Specified by:
        forEach in interface java.lang.Iterable<SearchField>
      • containsField

        public boolean containsField​(java.lang.String field)
        Get if this document contains field.
      • getField

        public SearchField getField​(java.lang.String field)
        Get a field or null if field does not exist.

        NOTE: if the field exists, but contains no field values, null will be returned.

      • setField

        public void setField​(SearchField field)
        Set a field for this document.

        If a field already exists with the same name, it will be replaced.

      • getFirstValue

        public SearchFieldValue getFirstValue​(java.lang.String field)
        Get the first SearchFieldValue for field or null if the field does not exist.
      • renameField

        public void renameField​(java.lang.String oldName,
                                java.lang.String newName)
        Rename a field.

        If the field does not exist no action is taken.

      • removeField

        public void removeField​(java.lang.String field)
        Remove a field from the document.
      • clear

        public void clear()
        Remove all fields and child documents.
      • addValues

        public void addValues​(java.lang.String field,
                              java.lang.String... values)
        Add String values to field.
      • addValues

        public void addValues​(java.lang.String field,
                              java.lang.Number... values)
        Add numeric values to field.
      • addValues

        public void addValues​(java.lang.String field,
                              java.util.Date... values)
        Add Date values to field.
      • addValues

        public void addValues​(java.lang.String field,
                              java.lang.Boolean... values)
        Add Boolean values to field.
      • addValues

        public void addValues​(java.lang.String field,
                              Point... values)
        Add Point values to field.
      • addValues

        public void addValues​(java.lang.String field,
                              Shape... values)
        Add Shape values to field.
      • addValue

        public void addValue​(java.lang.String field,
                             SearchFieldValue value)
        Add a value to field.
      • addValue

        public void addValue​(java.lang.String field,
                             java.lang.String value)
        Add a String value to field.
      • addValue

        public void addValue​(java.lang.String field,
                             java.lang.Number value)
        Add a numeric value to field.
      • addValue

        public void addValue​(java.lang.String field,
                             java.util.Date value)
        Add a Date value to field.
      • addValue

        public void addValue​(java.lang.String field,
                             java.lang.Boolean value)
        Add a Boolean value to field.
      • addValue

        public void addValue​(java.lang.String field,
                             Point value)
        Add a Point value to field.
      • addValue

        public void addValue​(java.lang.String field,
                             Shape value)
        Add a Shape value to field.
      • getTotalChildren

        public long getTotalChildren()
        Get the total number of child documents available or -1 if this count is not known or was not calculated.

        NOTE: the is the total number of possible child documents. Use getChildDocumentCount() to get the actual number of child documents returned with this SearchDocument.

      • setTotalChildren

        public void setTotalChildren​(long value)
        Set the total number of child documents available.
      • containsChildDocuments

        public boolean containsChildDocuments()
        Get if this document contains child records.
      • getChildDocumentCount

        public int getChildDocumentCount()
        Get the number of attached child documents.
      • getChildDocument

        public SearchDocument getChildDocument​(int index)
        Get a child document by index.
        Throws:
        java.lang.IndexOutOfBoundsException - if child document at index is not available.
      • getChildDocuments

        public java.lang.Iterable<SearchDocument> getChildDocuments()
        Get all of the available child documents.
      • setChildDocuments

        public void setChildDocuments​(SearchDocument... value)
        Set the child documents.
      • setChildDocuments

        public void setChildDocuments​(java.lang.Iterable<SearchDocument> value)
        Set the child documents.
      • addChildDocument

        public void addChildDocument​(SearchDocument value)
        Add a child document.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toString

        protected void toString​(java.lang.StringBuilder buffer,
                                int depth)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • clone

        public SearchDocument clone()
        Overrides:
        clone in class java.lang.Object
      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException
        Specified by:
        readExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException