DOCO 1.0.0

Document Converter for Google Search API

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

Download

How to use Doco?
See in the three steps below a simple example of using Doco. You'll really notice how easy is to work with Google Search API using Doco library.


1
Mapping the Post entity
Maps the fields you want to search in a document

Doco
              
@DocumentIndex
public class Post {
				
  @DocumentId
  private Long id;
  @DocumentField
  private String author;
  @DocumentField(type = FieldType.DATE)
  private Date creation;
  @DocumentField
  private String title;
  @DocumentField(type = FieldType.HTML)
  private String content;
  @DocumentField(type = FieldType.GEO_POINT)
  private GeoPoint location;
  private String notRelevantForSearch;
				  
  // getters and setters omitted
				  
}
			  
		    
Without Doco
              
public class Post {
				
  private Long id;
  private String author;
  private Date creation;
  private String title;
  private String content;
  private GeoPoint location;
  private String notRelevantForSearch;
				  
  // getters and setters omitted
				  
}







			  
		    

2
Putting the Post as a document in an index
Creates a document given a Post object and puts the document in an index

Doco
              
// just convert a Post to a Document
Doco doco = new Doco();
Document document = doco.toDocument(post);
 				
// gets an Index and saves the Document
Index index = doco.getIndex(Post.class);
index.put(document);
 				
 				
 				
 				
 				
 				
 				
 				
 				
 				
 				
 				
 				
 				
              
            
Without Doco
              
// creates a document with all Post fields
Document document = Document.newBuilder()
  .setId(post.getId().toString())
  .addField(Field.newBuilder().setName("author")
    .setText(post.getAuthor()))
  .addField(Field.newBuilder().setName("creation")
    .setDate(post.getCreation()))
  .addField(Field.newBuilder().setName("title")
    .setText(post.getTitle()))
  .addField(Field.newBuilder().setName("content")
    .setHTML(post.getContent()))
  .addField(Field.newBuilder().setName("location")
    .setGeoPoint(post.getLocation()))
  .build();
 				
// creates an Index and saves the Document
IndexSpec indexSpec = IndexSpec.newBuilder()
  .setName("Post").build(); 
Index index = SearchServiceFactory.getSearchService()
  .getIndex(indexSpec);
index.put(document);
              
            

3
Retrieving document as a Post object from index
Creates a Post object given a document retrieved from index

Doco
              
Doco doco = new Doco();
Index index = doco.getIndex(Post.class);
Document document = index.get(12345L);
 				
Post post = doco.fromDocument(document, Post.class);
 				


 				
 				
 				

 				
 				 				
 				
              
            
Without Doco
              
IndexSpec indexSpec = IndexSpec.newBuilder()
  .setName("Post").build(); 
Index index = SearchServiceFactory.getSearchService()
  .getIndex(indexSpec);
  				
Document document = index.get(12345L);
              
Post post = new Post();
post.setId(document.getId());
post.setAuthor(document.getOnlyField("author").getText());
post.setCreation(document.getOnlyField("creation").getDate());
post.setTitle(document.getOnlyField("title").getText());
post.setContent(document.getOnlyField("content").getHTML());
post.setLocation(document.getOnlyField("location")
  .getGeoPoint()); 				
              
            







Copyright 2014 Marcos Alexandre Vidolin de Lima