Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.google.appengine.api.search
Class Document

    java.lang.Object
      com.google.appengine.api.search.Document

All Implemented Interfaces:
  java.io.Serializable

    public final class Document

extends java.lang.Object
implements java.io.Serializable

Represents 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.

        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")))
           .addField(Field.newBuilder()
               .setName("tag")
               .setText("food"))
           .addField(Field.newBuilder()
               .setName("tag")
               .setText("friend"))
           .build();

The following example shows how to access the fields 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;
          }
        }

See Also:
  Serialized Form

Nested Class Summary
`static class` | `Document.Builder` A builder of documents.

Method Summary
`boolean` | `equals(java.lang.Object object)`
`java.lang.Iterable<Field>` | `getField(java.lang.String name)`
`int` | `getFieldCount(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()`
`java.lang.Iterable<Field>` | `getFields()`
`java.lang.String` | `getId()`
`java.util.Locale` | `getLocale()`
`Field` | `getOnlyField(java.lang.String name)` Returns the single field with the given name.
`int` | `getOrderId()`
`int` | `hashCode()`
`static Document.Builder` | `newBuilder()` Creates a new document builder.
`java.lang.String` | `toString()`

Methods inherited from class java.lang.Object
`getClass, notify, notifyAll, wait, wait, wait`

Method Detail

### getFields

    public java.lang.Iterable<Field> getFields()

  Returns:
    an iterable of `Field` in the document

### getFieldNames

    public java.util.Set<java.lang.String> getFieldNames()

  Returns:
    an unmodifiable `Set` of the field names in the document

### getField

    public java.lang.Iterable<Field> getField(java.lang.String name)

  Returns:
    an unmodifiable Iterable of `Field` with the given name, or `null`

### 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

### 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

### getId

    public java.lang.String getId()

  Returns:
    the id of the document

### getLocale

    public java.util.Locale getLocale()

  Returns:
    the `Locale` the document is written in. Can be null

### getOrderId

    public int getOrderId()

  Returns:
    the id used to return documents in a defined order in search results. If it was not specified, then the number of seconds since 2011/1/1 will be used

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `java.lang.Object`

### equals

    public boolean equals(java.lang.Object object)

  Overrides:
    `equals` in class `java.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 the `Document.Builder.build()` method on the returned builder.

  Returns:
    a builder which constructs a document object

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD