You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2008/04/04 11:41:52 UTC

svn commit: r644656 - /incubator/couchdb/branches/mochiweb/src/couchdb/couch_httpd.erl

Author: jan
Date: Fri Apr  4 02:41:50 2008
New Revision: 644656

URL: http://svn.apache.org/viewvc?rev=644656&view=rev
Log:
Refactor fulltext HTTP API handling: Less code, more pattern matching.

Modified:
    incubator/couchdb/branches/mochiweb/src/couchdb/couch_httpd.erl

Modified: incubator/couchdb/branches/mochiweb/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochiweb/src/couchdb/couch_httpd.erl?rev=644656&r1=644655&r2=644656&view=diff
==============================================================================
--- incubator/couchdb/branches/mochiweb/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/branches/mochiweb/src/couchdb/couch_httpd.erl Fri Apr  4 02:41:50 2008
@@ -122,21 +122,13 @@
 handle_replicate_request(_Req, _Method) ->
     throw({method_not_allowed, "POST"}).
 
-
 % Database request handlers
 
 handle_db_request(Req, Method, {Path}) ->
     UriParts = string:tokens(Path, "/"),
     [DbName|Rest] = UriParts,
-    UnquotedDbName = mochiweb_util:unquote(DbName),
-    case Rest of
-        ["_fulltext"|_] ->
-            handle_db_fulltext_request(Req, Method, UnquotedDbName);
-        _ ->
-            handle_db_request(Req, Method, {UnquotedDbName, Rest})
-    end;
+    handle_db_request(Req, Method, {mochiweb_util:unquote(DbName), Rest});
     
-
 handle_db_request(Req, 'PUT', {DbName, []}) ->
     case couch_server:create(DbName, []) of
         {ok, _Db} ->
@@ -231,6 +223,15 @@
 handle_db_request(_Req, _Method, {_DbName, _Db, ["_bulk_docs"]}) ->
     throw({method_not_allowed, "POST"});
 
+handle_db_request(Req, Method, {DbName, Db, ["_fulltext"]}) ->
+    case Req:parse_qs() of 
+        [{"q", Query}] ->
+            {ok, Response} = couch_ft_query:execute(DbName, Query),
+            send_json(Req, {obj, [{ok, true} | Response]});
+        _Error ->
+            throw({no_fulltext_query, "Empty Query String"})
+    end;
+
 % View request handlers
 
 handle_db_request(Req, 'GET', {_DbName, Db, ["_all_docs"]}) ->
@@ -371,15 +372,6 @@
 handle_db_request(Req, Method, {DbName, Db, [Resource]}) ->
     DocId = mochiweb_util:unquote(Resource),
     handle_doc_request(Req, Method, DbName, Db, DocId).
-
-handle_db_fulltext_request(Req, Method, UnquotedDbName) ->
-    case Req:parse_qs() of 
-        [{"q", Query}] ->
-            {ok, Response} = couch_ft_query:execute(UnquotedDbName, Query),
-            send_json(Req, {obj, [{ok, true} | Response]});
-        _Error ->
-            throw({no_fulltext_query, "Empty Query String"})
-    end.
 
 handle_doc_request(Req, 'DELETE', _DbName, Db, DocId) ->
     % TODO: Etag handling