Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.
/ doco Public archive

Doco - Document Converter for Google App Engine Search API

License

Notifications You must be signed in to change notification settings

marcosvidolin/doco

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Doco

Doco (Document Converter) is a lightweight Java library used to convert (from and to) indexed Documents provided by Search API in Google App Engine.

Homepage

http://www.vidolima.com/projects/doco

How to Use 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.

Annotations:

@DocumentIndex

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 {}

@DocumentId

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;

@DocumentField

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;

Field Types:

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

Conversions:

Once you map your entity its time to play with Doco.

Converting a Foo object to a Document and putting it in a index
// 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);
Getting the Document in an index and converting it to a Foo object.
// 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

Requirements

  • Java 1.5+
  • Google App Engine Java SDK 1.8.5+

TODO

  • Default type for: NUMBER, DATE and GEO_POINT
  • Convert collections

You can't do

  • 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)

See Also

Search API documentation https://developers.google.com/appengine/docs/java/search/

License

Doco is released under the terms of the MIT License.

Contributors