Slide 1

Slide 1 text

NoSQL on Android Sameer Segal http:/ /shinetechblog.files.wordpress.com/2011/11/android-on-couchdb.jpg?w=300&h=170 DroidCon - Bangalore | Nov 2nd, 2012

Slide 2

Slide 2 text

Sameer Segal Artoo (http:/ /artoo.in) ICT4D Primary Healthcare Financial Inclusion Clean-Tech Full-stack Engineer: WebSockets

Slide 3

Slide 3 text

App without Server http:/ /dorrys.com/wp-content/uploads/2009/11/fish_out_of_water.jpg ... fish out of water

Slide 4

Slide 4 text

http:/ /theultralinx.com/wp-content/uploads/2012/03/android_hotspot-620x465.png Connectivity - Online / Offline Push notifications Conflict Resolution

Slide 5

Slide 5 text

Time to Relax http:/ /4.bp.blogspot.com/-Y27tjnq3BLw/TxPvSHvtMPI/AAAAAAAAEkM/timXKQrA-ks/s1600/couchDB.png Document (JSON) Filtered Replication HTTP server

Slide 6

Slide 6 text

Todo MVC (Backbone) => CouchApp

Slide 7

Slide 7 text

Design Doc: Map / Reduce { _id: “_design/list_info”, map: function(doc) { if(doc.title) { emit(doc._id,doc); } }, / / Not using reduce reduce: function(key, values, rereduce) { return 1; }

Slide 8

Slide 8 text

CouchDB on Android Couchbase Mobile Data on SDCard Service Couch API Seed Data ARM 7+ Initial load time high TouchDB Wrapper around SQLite Couch like API Light weight http:/ /www.wittistribune.com/wp-content/uploads/2011/08/couchbase_mobile_screenshot.png http:/ /labs.couchbase.com/TouchDB-iOS/logo/TouchDBLogo1000px.png

Slide 9

Slide 9 text

CouchDB on Android couchbaselabs/TouchDB-Android

Slide 10

Slide 10 text

Grocery Sync (Couchbase) => Android App couchbaselabs/AndroidGrocerySync/tree/touchdb

Slide 11

Slide 11 text

Map / Reduce //install a view definition needed by the application TDDatabase db = server.getDatabaseNamed(DATABASE_NAME); TDView view = db.getViewNamed(String.format("%s/%s", dDocName, byOrderViewName)); view.setMapReduceBlocks(new TDViewMapBlock() { @Override public void map(Map document, TDViewMapEmitBlock emitter) { Object title = document.get("title"); if(title != null) { emitter.emit(document.get("_id").toString(), document); } } }, null, "1.0");

Slide 12

Slide 12 text

Replication pushReplicationCommand = new ReplicationCommand.Builder() .source(DATABASE_NAME) .target(prefs.getString("sync_url", "http://couchy.artoo.in/ todo")) .continuous(true) .build(); pullReplicationCommand = new ReplicationCommand.Builder() .source(prefs.getString("sync_url", "http://couchy.artoo.in/ todo")) .target(DATABASE_NAME) .continuous(true) .build();

Slide 13

Slide 13 text

Enter: http:/ /cdn.memegenerator.net/instances/400x/29437607 .jpg http:/ /windowsvj.com/wpblog/wp-content/uploads/2012/04/solr.jpg

Slide 14

Slide 14 text

CouchDB-Lucene Luke - Lucene Index Toolbox rnewson/couchdb-lucene http:/ /fukamachi.github.com/images/github-icon.jpg index: function(doc) { if(doc.name) { var ret = new Document(); ret.add(doc.title, {'field':'title','store':'yes'}); ret.add(doc.completed, {'field':'completed',' store':'yes',' index':'not_analyzed'}); return ret; } else { return null; } }

Slide 15

Slide 15 text

fetch_duration: 0, q: "title:d*", search_duration: 0, total_rows: 2, skip: 0, rows: [ { id: "a89f64228154c96206aaf71dcb227f84", score: 1, fields: { title: "Ensure demos are working correctly", completed: "false" } }, { id: "a89f64228154c96206aaf71dcb227c5c", score: 1, fields: { title: "Get to DroidCon on time", completed: "false" } } ]

Slide 16

Slide 16 text

TouchDB-Android-Lucene ArtooTrills/TouchDB-Android-Lucene Activity Define IndexStrategy TouchDB 1 2 Specify Query Lucene 3 Change Listener HTTP API Indexes stored on file storage

Slide 17

Slide 17 text

Location Queries

Slide 18

Slide 18 text

Location Queries https:/ /developers.google.com/appengine/articles/img/sf_onetile.png

Slide 19

Slide 19 text

Challenges TouchDB + TouchDB-Lucene = 7MB Share it between multiple apps through a service Rhino to the rescue TouchDB needs to reindex views every time it loads CouchDB Filters too slow Erlang improves performance by 30% (compared to JS) Seed the data using Lucene

Slide 20

Slide 20 text

Q?! Sameer Segal Founder & CEO, Artoo www.artoo.in