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 Summary
Fields Modifier and Type Field Description static int
classId
-
Constructor Summary
Constructors Constructor Description ReferenceFieldValue(ReferenceDataType referenceType)
Creates an empty reference of the provided reference type.ReferenceFieldValue(ReferenceDataType referenceType, DocumentId documentId)
Creates a reference pointing to a particular document instance in the document type referenced byreferenceType
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assign(Object o)
Assign this non-fieldvalue value to this field value.void
clear()
static ReferenceFieldValue
createEmptyWithType(ReferenceDataType referenceType)
void
deserialize(Field field, FieldReader reader)
Read a field value from the specified readerboolean
equals(Object o)
DataType
getDataType()
Optional<DocumentId>
getDocumentId()
DocumentId
getWrappedValue()
Expose target document ID as this value's wrapped value.int
hashCode()
void
printXml(XmlStream xml)
void
serialize(Field field, FieldWriter writer)
Write out field value to the specified writervoid
setDocumentId(DocumentId documentId)
String
toString()
-
Methods inherited from class com.yahoo.document.datatypes.FieldValue
clone, compareTo, create, deserialize, getRecursiveValue, getRecursiveValue, onDeserialize, onSerialize, serialize, toXml
-
-
-
-
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 byreferenceType
.- Parameters:
referenceType
- reference target typedocumentId
- document ID of the same document type as that given byreferenceType
- Throws:
IllegalArgumentException
- if documentId is not of the expected document type
-
-
Method Detail
-
createEmptyWithType
public static ReferenceFieldValue createEmptyWithType(ReferenceDataType referenceType)
-
getDataType
public DataType getDataType()
- Specified by:
getDataType
in classFieldValue
-
getDocumentId
public Optional<DocumentId> getDocumentId()
-
setDocumentId
public void setDocumentId(DocumentId documentId)
-
printXml
public void printXml(XmlStream xml)
- Specified by:
printXml
in classFieldValue
-
clear
public void clear()
- Specified by:
clear
in classFieldValue
-
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 classFieldValue
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classcom.yahoo.vespa.objects.Identifiable
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classcom.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 classFieldValue
-
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 classFieldValue
-
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 classFieldValue
- Returns:
- reference DocumentId, or null if none has been set
-
toString
public String toString()
- Overrides:
toString
in classcom.yahoo.vespa.objects.Identifiable
-
-