Hi!

Thanks for your response!
I am using this method only.

Currently I am defining view like this from Phonegap:
get_contacts:
{
map:  function(doc) {
if (doc.type && doc.is_active && doc.type == "contact")
{ 
emit(doc.type,doc)
}
}.toString()
}

But calling view from Phonegap is very slow!
Having this logs all the time.
02-14 00:45:05.685: D/dalvikvm(6462): WAIT_FOR_CONCURRENT_GC blocked 14ms
02-14 00:45:05.715: V/CBLDatabase(6462):   call map for sequence=14
02-14 00:45:05.750: D/dalvikvm(6462): GC_CONCURRENT freed 492K, 27% free 
13190K/17863K, paused 2ms+2ms, total 23ms

So, moving on native approach.

CBLDatabase db = server.getDatabaseNamed("jn_ami");
CBLView testView = db.getViewNamed("amiview");
testView.setMapReduceBlocks(new CBLViewMapBlock() {
 @Override
public void map(Map<String, Object> document, CBLViewMapEmitBlock emitter) {
if(document.get("type").equals("contact"))
{
emitter.emit(document.get("type"), null);
}
}
}, null, "1.1");
            
But it is not working when I call view "amiview" from phonegap.
So, any solution for this?

On Thursday, February 13, 2014 11:21:18 PM UTC+5:30, Traun Leyden wrote:
>
>
> I think there should be examples of that in 
> https://github.com/couchbaselabs/TodoLite-PhoneGap.
>
> It should essentially be the same as making a view query via REST to 
> CouchDB, so you can also check the CouchDB docs.
>
> @Chris -- I guess the recommended js library for talking to Couchbase Lite 
> from javascript is "coax/hoax" right?  Is there any others that people 
> should be aware of that will make their lives easier?  
>
> On Thursday, February 13, 2014, Ami Gandhi <[email protected]<javascript:>> 
> wrote:
>
>> Hi!
>> Can you tell me how to query CBLView from phonegap android?
>> Also, how to set startkey and endkey?
>>
>> On Monday, October 21, 2013 11:28:38 PM UTC+5:30, Traun Leyden wrote:
>>>
>>> Thanks for contributing this!
>>>
>>>
>>> On Sun, Oct 20, 2013 at 5:16 PM, Daniel Carr <[email protected]>wrote:
>>>
>>>> Thanks for your replies.
>>>>
>>>> If anyone is keen to try this, it's pretty easy. I know very little 
>>>> java and was able to work it out, and the performance is way better.
>>>>
>>>>
>>>> To get it to work, clone the git repo and import the modified cloned 
>>>> repo as a phonegap plugin:
>>>>
>>>> git clone https://github.com/couchbaselabs/Couchbase-Lite-
>>>>> PhoneGap-Plugin.git
>>>>> cd project
>>>>> phonegap local plugin add ../Couchbase-List-PhoneGap-Plugin
>>>>
>>>>
>>>> Every time you modify the plugin, you need to remove and add it again.
>>>>
>>>> phonegap local plugin remove com.couchbase.lite.phonegap
>>>>> phonegap local plugin add ../Couchbase-List-PhoneGap-Plugin
>>>>
>>>>
>>>>
>>>> As a proof of concept, I edited /src/android/CBLite.java file in 
>>>> Cordova-Lite-PhoneGap-Plugin.
>>>>
>>>> Add these to the imports:
>>>>
>>>> import com.couchbase.cblite.CBLDatabase;
>>>>> import com.couchbase.cblite.CBLViewMapBlock;
>>>>> import com.couchbase.cblite.CBLViewMapEmitBlock;
>>>>
>>>>
>>>> Remove the Javascript View thingy:
>>>>
>>>> -                       CBLView.setCompiler(new 
>>>>> CBLJavaScriptViewCompiler());
>>>>
>>>>
>>>>
>>>> Declare a view as described here: http://docs.couchbase.
>>>> com/couchbase-lite/cbl-android/#working-with-views
>>>>
>>>>
>>>>
>>>> e.g.: (sorry about the dodgy tabulation)
>>>>
>>>>
>>>> @@ -41,12 +45,25 @@ public class CBLite extends CordovaPlugin {
>>>>>  
>>>>>                         CBLURLStreamHandlerFactory.
>>>>> registerSelfIgnoreError();
>>>>>  
>>>>> -                       CBLView.setCompiler(new 
>>>>> CBLJavaScriptViewCompiler());
>>>>> -
>>>>>                         String filesDir = this.cordova.getActivity().
>>>>> getFilesDir()
>>>>>                                         .getAbsolutePath();
>>>>>                         CBLServer server = startCBLite(filesDir);
>>>>> -
>>>>> +                       
>>>>> +                       CBLDatabase db = server.getDatabaseNamed("
>>>>> treatment");
>>>>> +                       CBLView testView = db.getViewNamed("ivetTest/
>>>>> test");
>>>>> +                       testView.setMapReduceBlocks(new 
>>>>> CBLViewMapBlock() {
>>>>> +
>>>>> +                   @Override
>>>>> +                   public void map(Map<String, Object> document, 
>>>>> CBLViewMapEmitBlock emitter) {
>>>>> +                       String type = (String)document.get("Type");
>>>>> +                       if( "TreatmentRecord".equals(type) ) {
>>>>> +                           emitter.emit( document.get("_id"), 
>>>>> document.get("Location") );
>>>>> +                                       
>>>>> +                       }
>>>>> +
>>>>> +                   }
>>>>> +               }, null, "1.1"); 
>>>>> +                       
>>>>>                         listenPort = 
>>>>> startCBLListener(DEFAULT_LISTEN_PORT, 
>>>>> server);
>>>>>  
>>>>>                         System.out.println("initCBLite() completed 
>>>>> successfully");
>>>>
>>>>
>>>>  -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Mobile Couchbase" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Couchbase Mobile" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/mobile-couchbase/3bd01641-1b76-41fa-9164-ecf64ef35257%40googlegroups.com
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/bc488580-9fab-4f22-8a51-a0bc697e931f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to