benoitc / couchbeam

Apache CouchDB client in Erlang
Other
242 stars 113 forks source link

Patch to add support for arbitrary views, as couchdb-lucene _fti #15

Closed mdaguete closed 14 years ago

mdaguete commented 14 years ago

Hi Benoit,

This is a patch to add support for calling couchdb-lucene views,

diff --git a/src/couchbeam_view.erl b/src/couchbeam_view.erl
index 2c80733..db7de7e 100644                     
--- a/src/couchbeam_view.erl                      
+++ b/src/couchbeam_view.erl                      
@@ -76,7 +76,9 @@ init({Vname, Params, #db{server=ServerState, couchdb=CouchdbParams, base=BaseDB}
         '_all_docs_by_seq' ->                    
             io_lib:format("~s/_all_docs_by_seq", [BaseDB]);
         {DName, VName1} ->                       
-            io_lib:format("~s/_design/~s/_view/~s", [BaseDB, DName, VName1])
+            io_lib:format("~s/_design/~s/_view/~s", [BaseDB, DName, VName1]);
+        {AnotherBase,DName,VName1} ->            
+           io_lib:format("~s/~s/~s/~s",[BaseDB,AnotherBase,DName,VName1])
     end,                                         
     ViewState = #view{server    = ServerState,   
                       couchdb   = CouchdbParams, 

To use it: P = couchbeam_db:query_view(my_database,{"_fti", "search_docs","by_vendor_and_model"},[{<<"q">>,<<"Apple">>}]). couchbeam_view:parse_view(P).

I've not found another method to do it. If you think that the patch would be useful for another people add it to main stream.

Regards.

benoitc commented 14 years ago

Thanks for the patch. I just applied to latest HEAD :)