Skip to content
Browse files

fix external hook and external documentation.

  • Loading branch information...
1 parent c053a34 commit b9dc7a90284a5f39b44efe0848fff3a1b9ef888f Robert Newson committed Nov 20, 2009
Showing with 14 additions and 16 deletions.
  1. +1 −1 README.md
  2. +13 −11 couchdb-external-hook.py
  3. +0 −4 src/main/java/com/github/rnewson/couchdb/lucene/SearchServlet.java
View
2 README.md
@@ -39,7 +39,7 @@ You will now have a zip file in the target/ directory. This contains all the cou
os_process_timeout=60000 ; increase the timeout from 5 seconds.
[external]
-fti=/path/to/python /usr/lib/couchdb/couchdb-lucene/couchdb-external-hook.py --url="http://localhost:5985"
+fti=/path/to/python /usr/lib/couchdb/couchdb-lucene/couchdb-external-hook.py --host=localhost --port=5985
[httpd_db_handlers]
_fti = {couch_httpd_external, handle_external_req, <<"fti">>}
View
24 couchdb-external-hook.py
@@ -15,12 +15,15 @@
def options():
return [
- op.make_option('-u', '--url', dest='url',
+ op.make_option('--host', dest='host',
default="127.0.0.1",
- help="Host of the CouchDB-Lucene indexer. [%default]"),
- op.make_option('-p', '--port', dest='port', type='int',
+ help="Hostname of the couchdb-lucene server. [%default]"),
+ op.make_option('--port', dest='port', type='int',
default=5985,
- help="Port of the CouchDB-Lucene indexer. [%default]")
+ help="Port of the couchdb-lucene server. [%default]"),
+ op.make_option('--key', dest='key',
+ default="local",
+ help="Host key of this couchdb instance. [%default]")
]
def main():
@@ -29,15 +32,14 @@ def main():
if len(args):
parser.error("Unrecognized arguments: %s" % ' '.join(args))
-
- res = httplib.HTTPConnection(opts.url, opts.port)
+ res = httplib.HTTPConnection(opts.host, opts.port)
for req in requests():
try:
- resp = respond(res, req)
+ resp = respond(res, req, opts.key)
except Exception, e:
body = traceback.format_exc()
resp = mkresp(500, body, {"Content-Type": "text/plain"})
- res = httplib.HTTPConnection(opts.url, opts.port)
+ res = httplib.HTTPConnection(opts.host, opts.port)
sys.stdout.write(json.dumps(resp))
sys.stdout.write("\n")
@@ -49,18 +51,18 @@ def requests():
yield json.loads(line)
line = sys.stdin.readline()
-def respond(res, req):
+def respond(res, req, host_key):
path = req.get("path", [])
if len(path) != 4:
body = "\n".join([
"Invalid path: %s" % '/'.join([''] + path),
- "Paths should be: /db_name/_fti/docid/index_name?q=...",
+ "Paths should be: /host_key/db_name/_fti/docid/index_name?q=...",
"'docid' is from the '_design/docid' that defines index_name"
])
return mkresp(400, body, {"Content-Type": "text/plain"})
- path = '/'.join(['', 'search', path[0], path[2], path[3]])
+ path = '/'.join(['', 'search', host_key, path[0], path[2], path[3]])
path = '?'.join([path, urllib.urlencode(req["query"])])
req_headers = {}
View
4 src/main/java/com/github/rnewson/couchdb/lucene/SearchServlet.java
@@ -8,9 +8,7 @@
import java.io.IOException;
import java.io.Writer;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
import javax.servlet.ServletException;
@@ -61,8 +59,6 @@
private static final long serialVersionUID = 1L;
- private final Map<String, View> views = new HashMap<String, View>();
-
private Lucene lucene;
public void setLucene(final Lucene lucene) {

0 comments on commit b9dc7a9

Please sign in to comment.
Something went wrong with that request. Please try again.