FullText : query with REST API

226 views
Skip to first unread message

pierre houlle

unread,
Jan 21, 2014, 7:31:00 AM1/21/14
to mobile-c...@googlegroups.com
About fulltext queries with rest api, I followed the wiki by adding the parameter full_text, like this : 

I receive all the results of my view (the full text search does not work). 

I use the plugin couchbase-lite for cordova 3.2 on ios

I have missed something ?

Jens Alfke

unread,
Jan 21, 2014, 10:04:51 AM1/21/14
to mobile-c...@googlegroups.com, J Chris Anderson
On Jan 21, 2014, at 4:31 AM, pierre houlle <pierr...@gmail.com> wrote:

I receive all the results of my view (the full text search does not work). 

Hm, that query looks correct.

I use the plugin couchbase-lite for cordova 3.2 on ios

I haven't been keeping track of the status of the Cordova/PhoneGap plugin. Are you sure it's up to date with beta 2 of CBL? Full-text search wasn't in beta 1.
You could check by looking at the version reported by "GET /" — it's currently 1.49.

(Paging @jchris!)

—Jens

pierre houlle

unread,
Feb 19, 2014, 9:15:57 AM2/19/14
to mobile-c...@googlegroups.com
I forgot to say that I created the views by rest api  with the PUT method like that :

data :{ views : { myview : {
 map : function(doc){emit(doc.name)}.toString()
}}}


I saw,in iOS wiki, we need to add CBLTextKey() function to index the key, something like that : ... emit(CBLTextKey(doc.name))...

So, my question is : can we index some fields in a view by using rest api.

Jens Alfke

unread,
Feb 19, 2014, 3:28:48 PM2/19/14
to mobile-c...@googlegroups.com

On Feb 19, 2014, at 6:15 AM, pierre houlle <pierr...@gmail.com> wrote:

> So, my question is : can we index some fields in a view by using rest api.

Please see the wiki page on full-text search for details.

—Jens

Philipp Hecht

unread,
May 29, 2015, 11:55:03 AM5/29/15
to mobile-c...@googlegroups.com
Hello,

i also want to the full-text search. Is it correct that the api call only works in Coachbase Lite 2 beta?
I tried it with Coachbase Lite 1.0.4 it doesn' t work in combination with phonegap. Or i do something wrong.

My api call:

$ajax({
    url
: 'http://lite.coachbase./db/_design/design/view/_view/searchviewdoc?full_text=searchstring'
}).then(function(data){
var jsonstring = (JSON.stringify(data));
log
(jsonstring);
}
});



Thank for your answer.

Jens Alfke

unread,
May 29, 2015, 12:11:49 PM5/29/15
to mobile-c...@googlegroups.com
On May 29, 2015, at 6:57 AM, Philipp Hecht <philip...@bmtg.ch> wrote:

i also want to the full-text search. Is it correct that the api call only works in Coachbase Lite 2 beta?

1.0 beta 2 or later. (Assuming you’re using the iOS version of Couchbase Lite. It’s not on the other platforms.)

I tried it with Coachbase Lite 1.0.4 it doesn' t work in combination with phonegap. Or i do something wrong.

What does your map function look like?

—Jens
Message has been deleted
Message has been deleted

Philipp Hecht

unread,
May 31, 2015, 9:00:59 AM5/31/15
to mobile-c...@googlegroups.com
i use the IOS version of Cochbase Lite. Here is my map function. the view works only without the parameter full_text. when i add the parameter ?full_text=searchstring it doesn't work. I want to search in item_descr.

function setupViews(db, cb) {
        var design = "_design/view"
        db.put(design, {
            views: {
                searchviewdoc: {
                    map: function (doc) {
                        if (doc.type == "ITM" && doc.item_descr) {
                            emit(doc.id, doc.item_descr)
                    }
                    }.toString()
                },
            }
        }, function () {
            cb(false, db([design, "_view"]))
        })
    }

Jens Alfke

unread,
May 31, 2015, 1:40:18 PM5/31/15
to mobile-c...@googlegroups.com

On May 31, 2015, at 5:59 AM, Philipp Hecht <philip...@bmtg.ch> wrote:

i use the IOS version of Cochbase Lite. Here is my map function. the view works only when i add the parameter ?full_text=searchstring it doesn't work. I want to search in item_descr.

In a view that’s to be full-text indexed, the keys have to be emitted specially. In native code you use CBLTextKey( ) to create a full-text key, but there isn’t a JavaScript equivalent of that. So currently there’s no way to create a full-text index from JS, only to query it. Sorry :(

This wasn’t noted on the wiki page; I’ve updated it now.
Also, if you want to file an issue, we can try to fix this in the future.

—Jens

Philipp Hecht

unread,
Jun 1, 2015, 3:21:26 AM6/1/15
to mobile-c...@googlegroups.com
Jens, Thank you for your really fast response:-) . When i write the native code with CBLTextkey,  i can call the Index over the Api is that correct? At the moment the coachbase Lite Full text Search function is only supported for IOS? Is that correct?

Thank you

Philipp Hecht

unread,
Jun 1, 2015, 4:41:40 AM6/1/15
to mobile-c...@googlegroups.com
Is it eventually planned to create the index over javascript? or do you know a good solution how can i search full text offline (plattforms IOS, Android) over the coachbase lite database? Another solution is elasticsearch but you have to be online with your device.

Jens Alfke

unread,
Jun 1, 2015, 11:51:13 AM6/1/15
to mobile-c...@googlegroups.com
On Jun 1, 2015, at 12:21 AM, Philipp Hecht <philip...@bmtg.ch> wrote:

Jens, Thank you for your really fast response:-) . When i write the native code with CBLTextkey,  i can call the Index over the Api is that correct?

Yes, if you define the map function in native code and use CBLTextKey, you can query the view using the REST API.

At the moment the coachbase Lite Full text Search function is only supported for IOS? Is that correct?

Yes.

—Jens

Jens Alfke

unread,
Jun 1, 2015, 11:59:29 AM6/1/15
to mobile-c...@googlegroups.com
On Jun 1, 2015, at 1:41 AM, Philipp Hecht <philip...@bmtg.ch> wrote:

Is it eventually planned to create the index over javascript?

Probably, although we haven’t done any feature planning yet for how to bring FTS to other platforms/languages.

or do you know a good solution how can i search full text offline (plattforms IOS, Android) over the coachbase lite database? 

You can implement it yourself, but it won’t be as fast, and it won’t handle all the edge cases unless you do a lot of work.
The basic idea is to have the map function split the text into an array of words, then emit each word as a key. You need to:
  • lowercase the words
  • remove punctuation
  • remove common noise words like (in English) “the”, “a”, “an”, etc. These are called “stop words” and you can find lists of them online.
  • “stem” the words, which means removing variants like pluralization, verb conjugation, etc.
Then when you query, break the query string into words in the same way, and set the array as the query.keys property.

I’ve done this myself (to implement FTS on top of ForestDB). Stemming is the hardest part but you may be able to get away without it depending on the vocabulary in the text.

—Jens

Philipp Hecht

unread,
Jun 2, 2015, 2:30:37 PM6/2/15
to mobile-c...@googlegroups.com
thank you. Have you an example how can do this with CBLTextkey? 

Philipp Hecht

unread,
Jun 2, 2015, 2:30:44 PM6/2/15
to mobile-c...@googlegroups.com
Thank you.

Philipp Hecht

unread,
Jun 2, 2015, 2:31:25 PM6/2/15
to mobile-c...@googlegroups.com
Thank you Jens.

Jens Alfke

unread,
Jun 2, 2015, 3:43:48 PM6/2/15
to mobile-c...@googlegroups.com

On Jun 2, 2015, at 11:30 AM, Philipp Hecht <philip...@bmtg.ch> wrote:

thank you. Have you an example how can do this with CBLTextkey? 

The map block would be something like
if ([doc.type isEqualToString: @“catalogItem”])
emit(CBLTextKey(doc.lengthyDescription), doc.price);

—Jens
Reply all
Reply to author
Forward
0 new messages