Class ReferenceFieldValue

  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.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 Detail

      • classId

        public static final int classId
    • Constructor Detail

      • 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:
        java.lang.IllegalArgumentException - if documentId is not of the expected document type
    • Method Detail

      • getDocumentId

        public java.util.Optional<DocumentId> getDocumentId()
      • setDocumentId

        public void setDocumentId​(DocumentId documentId)
      • assign

        public void assign​(java.lang.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​(java.lang.Object o)
        Overrides:
        equals in class com.yahoo.vespa.objects.Identifiable
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class com.yahoo.vespa.objects.Identifiable
      • 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 java.lang.String toString()
        Overrides:
        toString in class com.yahoo.vespa.objects.Identifiable