Class ReferenceFieldValue

java.lang.Object
com.yahoo.vespa.objects.Selectable
com.yahoo.vespa.objects.Identifiable
com.yahoo.document.datatypes.FieldValue
com.yahoo.document.datatypes.ReferenceFieldValue
All Implemented Interfaces:
Cloneable, Comparable<FieldValue>

public class ReferenceFieldValue extends FieldValue

A reference field value allows search queries to access fields in other document instances as if they were fields natively stored within the searched document. This allows modelling one-to-many relations such as a parent document with many children containing references back to the parent.

Each ReferenceFieldValue may contain a single document ID which specifies the instance the field should refer to. This document ID must have a type matching that of the reference data type of the field itself.

Note that references are not polymorphic. This means that if you have a document type "foo" inheriting "bar", you cannot have a reference<bar> field containing a document ID for a "foo" document.

Author:
vekterli
  • Field Details

    • classId

      public static final int classId
  • Constructor Details

    • ReferenceFieldValue

      public ReferenceFieldValue(ReferenceDataType referenceType)
      Creates an empty reference of the provided reference type.
      Parameters:
      referenceType - reference target type
    • ReferenceFieldValue

      public ReferenceFieldValue(ReferenceDataType referenceType, DocumentId documentId)
      Creates a reference pointing to a particular document instance in the document type referenced by referenceType.
      Parameters:
      referenceType - reference target type
      documentId - document ID of the same document type as that given by referenceType
      Throws:
      IllegalArgumentException - if documentId is not of the expected document type
  • Method Details

    • createEmptyWithType

      public static ReferenceFieldValue createEmptyWithType(ReferenceDataType referenceType)
    • getDataType

      public DataType getDataType()
      Specified by:
      getDataType in class FieldValue
    • getDocumentId

      public Optional<DocumentId> getDocumentId()
    • setDocumentId

      public void setDocumentId(DocumentId documentId)
    • printXml

      public void printXml(XmlStream xml)
      Specified by:
      printXml in class FieldValue
    • clear

      public void clear()
      Specified by:
      clear in class FieldValue
    • assign

      public void assign(Object o)
      Description copied from class: FieldValue
      Assign this non-fieldvalue value to this field value. This is used to be able to assign ints to Integer field values and List to Array field values and such.

      Override to accept the specific types that should be legal.

      Specified by:
      assign in class FieldValue
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class com.yahoo.vespa.objects.Identifiable
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class com.yahoo.vespa.objects.Identifiable
    • serialize

      public void serialize(Field field, FieldWriter writer)
      Description copied from class: FieldValue
      Write out field value to the specified writer
      Specified by:
      serialize in class FieldValue
    • deserialize

      public void deserialize(Field field, FieldReader reader)
      Description copied from class: FieldValue
      Read a field value from the specified reader
      Specified by:
      deserialize in class FieldValue
    • getWrappedValue

      public DocumentId getWrappedValue()
      Expose target document ID as this value's wrapped value. Primarily implemented to allow for transparent interoperability when used in concrete document types.
      Overrides:
      getWrappedValue in class FieldValue
      Returns:
      reference DocumentId, or null if none has been set
    • toString

      public String toString()
      Overrides:
      toString in class com.yahoo.vespa.objects.Identifiable