couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Candler <B.Cand...@pobox.com>
Subject Re: Search feature ?
Date Sun, 17 Jan 2010 15:03:09 GMT
On Sun, Jan 17, 2010 at 03:19:59PM +0100, Nicolas Steinmetz wrote:
> For ex, I would like to implement a basic search in a blog app and maybe in
> the futur in a basic CRM app. So for ex if I search for couchdb, I would
> like to find all docs with couchdb in the title or body part in my blog and
> if I look for "Doe", I will find the entry I have for all people named "Doe"
> in my CRM app.
> 
> 
> > For example I use this function to "search" for animals in my database.
> > function (doc) {
> >    if (doc.doc_type == 'Animal') {
> >            emit(doc.ear_mark, doc);
> >            emit(doc.belt, doc);
> >            emit(doc.birth_date, doc);
> >    };
> > }
> > the user starts typing (either of these properties) in a text field
> > and is able to find the animal she is looking for.
> 
> 
> Looks it's what I was looking for.

That will let you find a title or body which *starts* with a given word or
text string.

If you want to search for a word within a title, it's possible to index the
words separately:

function (doc) {
  if (doc.title) {
    emit(doc.title, 'title');
    var words = doc.title.split(/[^a-z0-9]+/i);
    for (var i=1; i<words.length; i++) {
      if (words[i].length >= 3) {
        emit(words[i], 'title part');
      }
    }
  }
}

But for anything more sophisticated than that, you really want a plugin.

Note that couchdb's searching uses UCA collation by default. If the user
enters "Foo" as a search term then you should search for
  startkey="foo"&endkey="FOOZZZZZZZZ"

More info at: http://wiki.apache.org/couchdb/View_collation

Regards,

Brian.

Mime
View raw message