A similar condition in CouchDB

I want to fulfill a LIKE condition (SQL syntax) in CouchDB. How can this be done? The LIKE condition will be used to perform automatic completion in the browser.

I want to write "co" in the input field and get the results of Coffee, Couch, CouchDB, etc.

+5
source share
3 answers

It is very easy to find the letters at the beginning of a line. You just need a view that emits the string you want to find as a key. Assuming that user input is stored in a variable q, you call this view with the startkey=qand parameters endkey=q+"\ufff0".

, . - , q. ( , , @titanoboa, "" .)

(, " Colbert" "co" ), :

function(doc) {
  if (doc.title) {
    var words = {};
    doc.title.replace(/\w+/g, function(word) {
      words[word.toLowerCase()] = true;
    });
    for (w in words) {
      emit(w, doc);
    }
  }
}

, . , couchdb-lucene.

+9

CouchDB. Lucene, CouchDB. Lucene , , . .

0

To implement your example, you can create a view in which your field will be the key and the same field, the entire document or whatever you want as the value. If you request a view with parameters startkey="co", endkey="cp", inclusive_end=false, you will get all records with a key starting with "co".

Of course, this is less powerful than LIKE.

0
source

All Articles