Permalink
Browse files

Added example index definition for CouchDB-Lucene fulltext search engine

  • Loading branch information...
1 parent 989acda commit 29290b94ad1dd078f0ad8732241aa84a4c6b2dfc @karmi committed Sep 28, 2010
Showing with 27 additions and 0 deletions.
  1. +27 −0 couchdb/_design/person/fulltext/search/index.js
@@ -0,0 +1,27 @@
+// Default fulltext search index for the database
+// See: http://github.com/rnewson/couchdb-lucene
+
+// http://localhost:5984/addressbook/_fti/_design/person/search?q=occupation:supermodel AND city:<CITY>
+
+function(doc) {
+
+ var result = new Document();
+
+ if (doc.last_name) { result.add(doc.last_name, {"field":"last_name"}) }
+ if (doc.occupation) { result.add(doc.occupation, {"field":"occupation"}) }
+
+ if (doc.addresses) {
+ for (address in doc.addresses) {
+ result.add(doc.addresses[address].city, {"field":"city"})
+ result.add(doc.addresses[address].country, {"field":"country"})
+ }
+ }
+
+ if (doc.birthday) {
+ // Date string should be in format: YYYY/mm/dd HH:MM:SS
+ result.add(new Date(doc.birthday), {"field":"birthday", "type":"date"});
+ }
+
+ return result;
+
+}

0 comments on commit 29290b9

Please sign in to comment.