Giter Site home page Giter Site logo

marcosvidolin / doco Goto Github PK

View Code? Open in Web Editor NEW
16.0 5.0 6.0 103 KB

Doco - Document Converter for Google App Engine Search API

License: MIT License

Java 100.00%
google gae app-engine-search-api search-api document search google-appengine java doco document-converter entity

doco's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.