Package com.yahoo.document
Class Document
- java.lang.Object
-
- com.yahoo.vespa.objects.Selectable
-
- com.yahoo.vespa.objects.Identifiable
-
- All Implemented Interfaces:
java.lang.Cloneable
,java.lang.Comparable<FieldValue>
public class Document extends StructuredFieldValue
A document is an identifiable set of value bindings of adocument 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 Modifier and Type Field Description static int
classId
static short
SERIALIZED_VERSION
-
Constructor Summary
Constructors Constructor Description Document(Document doc)
Creates 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, java.lang.String id)
Create a document with the given document type and identifier.Document(DocumentReader reader)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
assign(java.lang.Object o)
Assign this non-fieldvalue value to this field value.void
clear()
Document
clone()
int
compareTo(FieldValue fieldValue)
static Document
createDocument(DocumentReader buffer)
void
deserialize(Field field, FieldReader reader)
Read a field value from the specified readervoid
deserialize(DocumentReader reader)
protected void
doSetFieldValue(Field field, FieldValue value)
boolean
equals(java.lang.Object o)
Returns true if the argument is a document which has the same set of valuesint
getApproxSize()
This is an approximation of serialized size.Struct
getBody()
Deprecated.do not use: Use getField(), getFieldValue() or iterator() insteadDocumentType
getDataType()
Field
getField(java.lang.String fieldName)
Returns the named field object, or null if that field does not exist.int
getFieldCount()
FieldValue
getFieldValue(Field field)
Returns the value of the given field.Struct
getHeader()
Deprecated.do not use: Use getField(), getFieldValue() or iterator() insteadDocumentId
getId()
java.lang.Long
getLastModified()
Returns the last modified time of this Document, when stored in persistent storage.int
getSerializedSize()
int
hashCode()
java.util.Iterator<java.util.Map.Entry<Field,FieldValue>>
iterator()
void
onSerialize(com.yahoo.vespa.objects.Serializer data)
void
printXml(XmlStream xml)
FieldValue
removeFieldValue(Field field)
Removes and returns a field value.void
serialize(Field field, FieldWriter writer)
Write out field value to the specified writervoid
serialize(DocumentWriter writer)
void
serialize(java.io.OutputStream out)
void
setDataType(DataType type)
void
setId(DocumentId id)
void
setLastModified(java.lang.Long lastModified)
Sets the last modified time of this Document.java.lang.String
toJson()
Get JSON representation of the document root and its children contained in a JSON objectjava.lang.String
toString()
java.lang.String
toXml()
Get XML representation of the document root and its children, contained within a <document></document> tag.java.lang.String
toXML(java.lang.String indent)
-
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, setFieldValue
-
Methods inherited from class com.yahoo.document.datatypes.FieldValue
create, deserialize, getRecursiveValue, getRecursiveValue, getWrappedValue, onDeserialize, serialize
-
-
-
-
Field Detail
-
classId
public static final int classId
-
SERIALIZED_VERSION
public static final short SERIALIZED_VERSION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Document
public Document(DocumentType docType, java.lang.String id)
Create a document with the given document type and identifier.- Parameters:
docType
- DocumentType to use for creationid
- The id for this document
-
Document
public Document(DocumentType docType, DocumentId id)
Create a document with the given document type and identifier.- Parameters:
docType
- DocumentType to use for creationid
- The id for this document
-
Document
public Document(Document doc)
Creates a document that is a shallow copy of another.- Parameters:
doc
- The document to copy.
-
Document
public Document(DocumentReader reader)
- Parameters:
reader
- The deserializer to use for creating this document
-
-
Method Detail
-
getId
public DocumentId getId()
-
setId
public void setId(DocumentId id)
-
getHeader
@Deprecated public Struct getHeader()
Deprecated.do not use: Use getField(), getFieldValue() or iterator() instead
-
getBody
@Deprecated public Struct getBody()
Deprecated.do not use: Use getField(), getFieldValue() or iterator() instead
-
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 classFieldValue
-
clone
public Document clone()
- Overrides:
clone
in classFieldValue
-
setDataType
public void setDataType(DataType type)
- Overrides:
setDataType
in classCompositeFieldValue
-
getSerializedSize
public int getSerializedSize() throws SerializationException
- 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
public void serialize(java.io.OutputStream out) throws SerializationException
- Throws:
SerializationException
-
createDocument
public static Document createDocument(DocumentReader buffer)
-
getField
public Field getField(java.lang.String fieldName)
Description copied from class:StructuredFieldValue
Returns the named field object, or null if that field does not exist.- Specified by:
getField
in classStructuredFieldValue
- Parameters:
fieldName
- The name of the field to return.- Returns:
- The corresponding field, or null.
-
getFieldValue
public FieldValue getFieldValue(Field field)
Description copied from class:StructuredFieldValue
Returns the value of the given field. If the field does not exist, this method returns null.- Specified by:
getFieldValue
in classStructuredFieldValue
- Parameters:
field
- The field whose value to return.- Returns:
- The value of the field, or null.
-
doSetFieldValue
protected void doSetFieldValue(Field field, FieldValue value)
- Specified by:
doSetFieldValue
in classStructuredFieldValue
-
removeFieldValue
public FieldValue removeFieldValue(Field field)
Description copied from class:StructuredFieldValue
Removes and returns a field value.- Specified by:
removeFieldValue
in classStructuredFieldValue
- Parameters:
field
- The field whose value to remove.- Returns:
- The previous value of the field, or null.
-
clear
public void clear()
- Specified by:
clear
in classStructuredFieldValue
-
iterator
public java.util.Iterator<java.util.Map.Entry<Field,FieldValue>> iterator()
- Specified by:
iterator
in classStructuredFieldValue
-
toString
public java.lang.String toString()
- Overrides:
toString
in classcom.yahoo.vespa.objects.Identifiable
-
toXML
public java.lang.String toXML(java.lang.String indent)
-
toXml
public java.lang.String toXml()
Get XML representation of the document root and its children, contained within a <document></document> tag.- Overrides:
toXml
in classFieldValue
- Returns:
- XML representation of document
-
printXml
public void printXml(XmlStream xml)
- Specified by:
printXml
in classFieldValue
-
toJson
public java.lang.String toJson()
Get JSON representation of the document root and its children contained in a JSON object- Returns:
- JSON representation of document
-
equals
public boolean equals(java.lang.Object o)
Returns true if the argument is a document which has the same set of values- Overrides:
equals
in classCompositeFieldValue
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classCompositeFieldValue
-
getLastModified
public java.lang.Long 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
public void setLastModified(java.lang.Long lastModified)
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
public void onSerialize(com.yahoo.vespa.objects.Serializer data) throws SerializationException
- Overrides:
onSerialize
in classFieldValue
- Throws:
SerializationException
-
getDataType
public DocumentType getDataType()
- Overrides:
getDataType
in classStructuredFieldValue
-
getFieldCount
public int getFieldCount()
- Specified by:
getFieldCount
in classStructuredFieldValue
-
serialize
public void serialize(DocumentWriter writer)
-
deserialize
public void deserialize(DocumentReader reader)
-
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
-
compareTo
public int compareTo(FieldValue fieldValue)
- Specified by:
compareTo
in interfacejava.lang.Comparable<FieldValue>
- Overrides:
compareTo
in classFieldValue
-
-