Doco (Document Converter) is a lightweight Java library used to convert (from and to) indexed Documents provided by Search API in Google App Engine.
http://www.vidolima.com/projects/doco
Before converting objects to documents (or vice versa), you need to tell Doco which fields will be used. Maps the fields you want to search in a document with following annotations.
This annotation is applied to the entity class. This annotation defines the name of the IndexSpec. Doco by default assume the name of the class as index id
// the name of the index id will be "Foo"
@DocumentIndex
public class Foo {}
You can set the index id as you want using the parameter name
@DocumentIndex(name = "customIndexId")
public class Foo {}
Place this annotation on fields of an entity POJO. This field defines the id of the document. The type of a field annotated with DocumentId must be Integer, Long or String.
@DocumentId
private Long id;
You can specify a name to an id using name parameter
@DocumentId(name = "otherIdName")
private Long id;
Place this annotation on fields of an entity POJO. This annotation defines a field of a document. All fields must have a name and a type (see all types here). Doco assumes the same name of the annotated property to the name of the document field if the name was not specified, and assumes TEXT type by default.
@DocumentField
private String textField;
Use de name property to specify a name to the field
@DocumentField(name = "otherName")
private String textField;
You can specify the field type using the type parameter
@DocumentField(type = FieldType.NUMBER)
private Double total;
These are all valid types you can use to specify a document field with a "type" parameter in a @DocumentField annotation.
Atom Field - an indivisible character string
FieldType.ATOM
Text Field - a plain text string that can be searched word by word
FieldType.TEXT
Number Field - an Integer, Double, Float or Long field
FieldType.NUMBER
HTML Field - a string that contains HTML markup tags, only the text outside the markup tags can be searched
FieldType.HTML
Date Field - a date object with year/month/day and optional time
FieldType.DATE
Geopoint Field - a data object with latitude and longitude coordinates
FieldType.GEO_POINT
Once you map your entity its time to play with Doco.
// just convert a Foo to a Document
Doco doco = new Doco();
Document document = doco.toDocument(foo);
// gets an Index and saves the Document
Index index = doco.getIndex(Foo.class);
index.put(document);
// gets the document from index
Doco doco = new Doco();
Index index = doco.getIndex(Foo.class);
Document document = index.get(12345L);
// simple way to convert a document to a Foo
Foo foo = doco.fromDocument(document, Foo.class);
See the [site] (http://www.vidolima.com/projects/doco) for more details
- Java 1.5+
- Google App Engine Java SDK 1.8.5+
- Default type for: NUMBER, DATE and GEO_POINT
- Convert collections
- A document with multiple fields with the same name
- A NUMBER field value must be less than or equal to 2147483647.000000 (Google Search API limitation)
Search API documentation https://developers.google.com/appengine/docs/java/search/
Doco is released under the terms of the MIT License.