com.google.appengine.api.search
Class Document
- java.lang.Object
-
- com.google.appengine.api.search.Document
-
- All Implemented Interfaces:
- java.io.Serializable
- Direct Known Subclasses:
- ScoredDocument
public class Document extends java.lang.Object implements java.io.SerializableRepresents a user generated document. The following example shows how to create a document consisting of a set of fields, some with plain text and some in HTML; it also adds facets to the document. The following example shows how to access the fields within a document:Document document = Document.newBuilder().setId("document id") .setLocale(Locale.UK) .addField(Field.newBuilder() .setName("subject") .setText("going for dinner")) .addField(Field.newBuilder() .setName("body") .setHTML("<html>I found a restaurant.</html>")) .addField(Field.newBuilder() .setName("signature") .setText("ten post jest przeznaczony dla odbiorcy") .setLocale(new Locale("pl"))) .addFacet(Facet.withAtom("tag", "food")) .addFacet(Facet.withNumber("priority", 5.0)) .build(); And this example shows how to access the facets within a document:Document document = ... for (Field field : document.getFields()) { switch (field.getType()) { case TEXT: use(field.getText()); break; case HTML: use(field.getHtml()); break; case ATOM: use(field.getAtom()); break; case DATE: use(field.getDate()); break; } }Document document = ... for (Facet facet : document.getFacets()) { switch (facet.getType()) { case ATOM: use(facet.getAtom()); break; case NUMBER: use(facet.getNumber()); break; } }- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classDocument.BuilderA builder of documents.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanequals(java.lang.Object object)intgetFacetCount(java.lang.String name)Returns the number of times a facet with the given name is present in this document.java.util.Set<java.lang.String>getFacetNames()Returns an unmodifiableSetof the facet names in the documentjava.lang.Iterable<Facet>getFacets()Returns an iterable ofFacetin the documentjava.lang.Iterable<Facet>getFacets(java.lang.String name)Returns an iterable of all facets with the given name.intgetFieldCount(java.lang.String name)Returns the number of times a field with the given name is present in this document.java.util.Set<java.lang.String>getFieldNames()Returns an unmodifiableSetof the field names in the documentjava.lang.Iterable<Field>getFields()Returns an iterable ofFieldin the documentjava.lang.Iterable<Field>getFields(java.lang.String name)Returns an iterable of all fields with the given name.java.lang.StringgetId()java.util.LocalegetLocale()FacetgetOnlyFacet(java.lang.String name)Returns the single facet with the given name.FieldgetOnlyField(java.lang.String name)Returns the single field with the given name.intgetRank()Returns the rank of this document.inthashCode()static Document.BuildernewBuilder()Creates a new document builder.java.lang.StringtoString()
-
-
-
Method Detail
-
getFieldNames
public java.util.Set<java.lang.String> getFieldNames()
Returns an unmodifiableSetof the field names in the document
-
getFacetNames
public java.util.Set<java.lang.String> getFacetNames()
Returns an unmodifiableSetof the facet names in the document
-
getFields
public java.lang.Iterable<Field> getFields(java.lang.String name)
Returns an iterable of all fields with the given name.- Parameters:
name- the name of the field whose values are to be returned- Returns:
- an unmodifiable
IterableofFieldwith the given name ornull
-
getFacets
public java.lang.Iterable<Facet> getFacets(java.lang.String name)
Returns an iterable of all facets with the given name.- Parameters:
name- the name of the facet whose values are to be returned- Returns:
- an unmodifiable
IterableofFacetwith the given name ornull
-
getOnlyField
public Field getOnlyField(java.lang.String name)
Returns the single field with the given name.- Parameters:
name- the name of the field to return- Returns:
- the single field with name
- Throws:
java.lang.IllegalArgumentException- if the document does not have exactly one field with the name
-
getOnlyFacet
public Facet getOnlyFacet(java.lang.String name)
Returns the single facet with the given name.- Parameters:
name- the name of the facet to return- Returns:
- the single facet with name
- Throws:
java.lang.IllegalArgumentException- if the document does not have exactly one facet with the name
-
getFieldCount
public int getFieldCount(java.lang.String name)
Returns the number of times a field with the given name is present in this document.- Parameters:
name- the name of the field to be counted- Returns:
- the number of times a field with the given name is present
-
getFacetCount
public int getFacetCount(java.lang.String name)
Returns the number of times a facet with the given name is present in this document.- Parameters:
name- the name of the facet to be counted- Returns:
- the number of times a facet with the given name is present
-
getId
public java.lang.String getId()
- Returns:
- the id of the document
-
getLocale
public java.util.Locale getLocale()
- Returns:
- the
Localethe document is written in. Can be null
-
getRank
public int getRank()
Returns the rank of this document. A document's rank is used to determine the default order in which documents are returned by search, if no sorting or scoring is specified.- Returns:
- the rank of this document
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
newBuilder
public static Document.Builder newBuilder()
Creates a new document builder. You must use this method to obtain a new builder. The returned builder must be used to specify all properties of the document. To obtain the document call theDocument.Builder.build()method on the returned builder.- Returns:
- a builder which constructs a document object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-