Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding a couchdb.php view initialization script.

  • Loading branch information...
commit 8f13c98859b810ac217626e7b65ac22ce0788a9f 1 parent 2e11a37
@jhedstrom jhedstrom authored eby committed
Showing with 33 additions and 0 deletions.
  1. +33 −0 sql/couchdb.php
View
33 sql/couchdb.php
@@ -0,0 +1,33 @@
+#!/usr/bin/php
+<?php
+/**
+ * @file
+ * Initialize the sphinx view.
+ */
+chdir('..');
+require_once 'locum.php';
+
+$locum = new locum;
+$client = new couchClient($locum->couchserver, $locum->couchdatabase);
+
+// Create the view.
+try {
+ $doc = $client->getDoc('_design/sphinx');
+} catch ( Exception $e ) {
+ if ( $e->getCode() == 404 ) {
+ // document doesn't exist. create a new one
+ $doc = new stdClass();
+ $doc->_id = '_design/sphinx';
+ }
+ else {
+ var_dump($e);
+ exit;
+ }
+}
+
+$doc->views = new stdClass;
+$doc->views->by_sphinxid = new stdClass;
+$doc->views->by_sphinxid->map = "function(doc) { if (doc.bnum) { emit(doc.bnum, null); } }";
+
+// Save view.
+$client->storeDoc($doc);
Please sign in to comment.
Something went wrong with that request. Please try again.