Package com.yahoo.document
Class Document
java.lang.Object
com.yahoo.vespa.objects.Selectable
com.yahoo.vespa.objects.Identifiable
- All Implemented Interfaces:
Cloneable,Comparable<FieldValue>
A document is an identifiable
set of value bindings of a
document type.
A document represents an instance of some entity of interest
in an application, like an article, a web document, a product, etc.
Deprecation: Try to use document set and get methods only with FieldValue types,
not with primitive types. Support for direct access to primitive types will
be removed soon.- Author:
- bratseth, Einar M R Rosenvinge
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a document that is a shallow copy of another.Document(DocumentType docType, DocumentId id) Create a document with the given document type and identifier.Document(DocumentType docType, String id) Create a document with the given document type and identifier.Document(DocumentReader reader) -
Method Summary
Modifier and TypeMethodDescriptionvoidAssign this non-fieldvalue value to this field value.voidclear()clone()intcompareTo(FieldValue fieldValue) static DocumentcreateDocument(DocumentReader buffer) voiddeserialize(Field field, FieldReader reader) Read a field value from the specified readervoiddeserialize(DocumentReader reader) protected voiddoSetFieldValue(Field field, FieldValue value) booleanReturns true if the argument is a document which has the same set of valuesfinal intThis is an approximation of serialized size.Returns the named field object, or null if that field does not exist.intgetFieldValue(Field field) Returns the value of the given field.getId()Returns the last modified time of this Document, when stored in persistent storage.intinthashCode()iterator()voidonSerialize(com.yahoo.vespa.objects.Serializer data) voidDeprecated.removeFieldValue(Field field) Removes and returns a field value.voidserialize(Field field, FieldWriter writer) Write out field value to the specified writervoidserialize(DocumentWriter writer) voidserialize(OutputStream out) voidsetDataType(DataType type) voidsetId(DocumentId id) voidsetLastModified(Long lastModified) Sets the last modified time of this Document.toJson()Get JSON representation of the document root and its children contained in a JSON objecttoString()toXml()Deprecated.Deprecated.Methods inherited from class com.yahoo.document.datatypes.StructuredFieldValue
getFieldValue, isGenerated, iterateNested, removeFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValueMethods inherited from class com.yahoo.document.datatypes.FieldValue
create, deserialize, getRecursiveValue, getRecursiveValue, getWrappedValue, onDeserialize, serializeMethods inherited from class com.yahoo.vespa.objects.Identifiable
create, createFromId, deserialize, deserializeOptional, deserializeWithId, equals, getClassId, getRawUtf8Bytes, getUtf8, onGetClassId, putUtf8, registerClass, registerClass, serialize, serializeOptional, serializeWithId, visitMembersMethods inherited from class com.yahoo.vespa.objects.Selectable
select, select, selectMembers
-
Field Details
-
classId
public static final int classId -
SERIALIZED_VERSION
public static final short SERIALIZED_VERSION- See Also:
-
-
Constructor Details
-
Document
Create a document with the given document type and identifier.- Parameters:
docType- DocumentType to use for creationid- The id for this document
-
Document
Create a document with the given document type and identifier.- Parameters:
docType- DocumentType to use for creationid- The id for this document
-
Document
Creates a document that is a shallow copy of another.- Parameters:
doc- The document to copy.
-
Document
- Parameters:
reader- The deserializer to use for creating this document
-
-
Method Details
-
getId
-
setId
-
assign
Description copied from class:FieldValueAssign 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:
assignin classFieldValue
-
clone
- Overrides:
clonein classFieldValue
-
setDataType
- Overrides:
setDataTypein classCompositeFieldValue
-
getSerializedSize
- Throws:
SerializationException
-
getApproxSize
public final int getApproxSize()This is an approximation of serialized size. We just set it to 4096 as a definition of a medium document.- Returns:
- Approximate size of document (4096)
-
serialize
- Throws:
SerializationException
-
createDocument
-
getField
Description copied from class:StructuredFieldValueReturns the named field object, or null if that field does not exist.- Specified by:
getFieldin classStructuredFieldValue- Parameters:
fieldName- The name of the field to return.- Returns:
- The corresponding field, or null.
-
getFieldValue
Description copied from class:StructuredFieldValueReturns the value of the given field. If the field does not exist, this method returns null.- Specified by:
getFieldValuein classStructuredFieldValue- Parameters:
field- The field whose value to return.- Returns:
- The value of the field, or null.
-
doSetFieldValue
- Specified by:
doSetFieldValuein classStructuredFieldValue
-
removeFieldValue
Description copied from class:StructuredFieldValueRemoves and returns a field value.- Specified by:
removeFieldValuein classStructuredFieldValue- Parameters:
field- The field whose value to remove.- Returns:
- The previous value of the field, or null.
-
clear
public void clear()- Specified by:
clearin classStructuredFieldValue
-
iterator
- Specified by:
iteratorin classStructuredFieldValue
-
toString
- Overrides:
toStringin classcom.yahoo.vespa.objects.Identifiable
-
toXML
Deprecated. -
toXml
Deprecated.Get XML representation of the document root and its children, contained within a <document></document> tag.- Overrides:
toXmlin classFieldValue- Returns:
- XML representation of document
-
printXml
Deprecated.- Specified by:
printXmlin classFieldValue
-
toJson
Get JSON representation of the document root and its children contained in a JSON object- Returns:
- JSON representation of document
-
equals
Returns true if the argument is a document which has the same set of values- Overrides:
equalsin classCompositeFieldValue
-
hashCode
public int hashCode()- Overrides:
hashCodein classCompositeFieldValue
-
getLastModified
Returns the last modified time of this Document, when stored in persistent storage. This is typically set by the library that retrieves the Document from persistent storage. This variable doesn't really belong in document. It is used when retrieving docblocks of documents to be able to see when documents was last modified in VDS, without having to add modified times separate in the API. NOTE: This is a transient field, and will not be serialized with a Document (will be null after deserialization).- Returns:
- the last modified time of this Document (in milliseconds), or null if unset
-
setLastModified
Sets the last modified time of this Document. This is typically set by the library that retrieves the Document from persistent storage, and should not be set by arbitrary clients. NOTE: This is a transient field, and will not be serialized with a Document (will be null after deserialization).- Parameters:
lastModified- the last modified time of this Document (in milliseconds)
-
onSerialize
- Overrides:
onSerializein classFieldValue- Throws:
SerializationException
-
getDataType
- Overrides:
getDataTypein classStructuredFieldValue
-
getFieldCount
public int getFieldCount()- Specified by:
getFieldCountin classStructuredFieldValue
-
serialize
-
deserialize
-
serialize
Description copied from class:FieldValueWrite out field value to the specified writer- Specified by:
serializein classFieldValue
-
deserialize
Description copied from class:FieldValueRead a field value from the specified reader- Specified by:
deserializein classFieldValue
-
compareTo
- Specified by:
compareToin interfaceComparable<FieldValue>- Overrides:
compareToin classFieldValue
-