You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Hermes Alves <he...@softagon.com.br> on 2015/06/11 00:44:01 UTC

Search on Couchd using AngularJS

Hello,

I'm a newbie on CouchDB. Thanks for your patience :)

I need to find by keword on couchdb databse use a query type "Like %key%"

Anyone can help me to do this using AngularJS? I already searched on
Google, but i can't find a functional sample.

-- 

*Hermes Alves Dias Souza*
Gestor
hermes@softagon.com.br
------------------------------
[image: Visite o site] <http://www.softagon.com.br/>Softagon Inovação
87 3873 4978
www.softagon.com.br

-- 

------------------------------
[image: Visite o site] <http://www.softagon.com.br/>
Softagon Inovação 
87 3873 4978
www.softagon.com.br

Re: Search on Couchd using AngularJS

Posted by Joel Wallis <jo...@gmail.com>.
You'll probably need to write a view. You can read the documentation for
this feature at:

http://docs.couchdb.org/en/1.6.1/couchapp/views/intro.html

2015-06-10 19:44 GMT-03:00 Hermes Alves <he...@softagon.com.br>:

> Hello,
>
> I'm a newbie on CouchDB. Thanks for your patience :)
>
> I need to find by keword on couchdb databse use a query type "Like %key%"
>
> Anyone can help me to do this using AngularJS? I already searched on
> Google, but i can't find a functional sample.
>
> --
>
> *Hermes Alves Dias Souza*
> Gestor
> hermes@softagon.com.br
> ------------------------------
> [image: Visite o site] <http://www.softagon.com.br/>Softagon Inovação
> 87 3873 4978
> www.softagon.com.br
>
> --
>
> ------------------------------
> [image: Visite o site] <http://www.softagon.com.br/>
> Softagon Inovação
> 87 3873 4978
> www.softagon.com.br
>



-- 
Joel Wallis Jucá
joelwallis.com

Re: Search on Couchd using AngularJS

Posted by Antoine Duchâteau <ad...@gmail.com>.
This kind of query is not typically what CouchDB was built for. You can 
nonetheless achieve what you wish by building a view (like this).

functionemit_normalized_substrings(txt) {
     varr=txt.toLowerCase();
     r=r.replace(newRegExp("\\s",'g'),"");
     r=r.replace(newRegExp("[àáâãäå]",'g'),"a");
     r=r.replace(newRegExp("æ",'g'),"ae");
     r=r.replace(newRegExp("ç",'g'),"c");
     r=r.replace(newRegExp("[èéêë]",'g'),"e");
     r=r.replace(newRegExp("[ìíîï]",'g'),"i");
     r=r.replace(newRegExp("ñ",'g'),"n");
     r=r.replace(newRegExp("[òóôõö]",'g'),"o");
     r=r.replace(newRegExp("œ",'g'),"oe");
     r=r.replace(newRegExp("[ùúûü]",'g'),"u");
     r=r.replace(newRegExp("[ÿ]",'g'),"y");
     r=r.replace(newRegExp("\\W",'g'),"");

     for(vari=0;i<=r.length-3;i++) {
         emit(r.substr(i,r.length-i),docId);
     }
}

map=function(doc) {
     emit_normalized_substrings(doc.fieldYouWantToQuery);
};


For "Hermes":

hermes: id of your doc
ermes: id of your doc
rmes: id of your doc
mes : id of your doc

are going to be emitted.

A range query erm -> erm\uffff will be equivalent to %erm%
Note that you need min 3 characters for your query to work with this view.

Cheers,
Antoine
> Hermes Alves <ma...@softagon.com.br>
> 11 juin 2015 00:44
> Hello,
>
> I'm a newbie on CouchDB. Thanks for your patience :)
>
> I need to find by keword on couchdb databse use a query type "Like %key%"
>
> Anyone can help me to do this using AngularJS? I already searched on
> Google, but i can't find a functional sample.
>

Re: Search on Couchd using AngularJS

Posted by Aurélien Bénel <au...@utt.fr>.
Hi Hermes,

> I need to find by keword on couchdb databse use a query type "Like %key%"

Can you be more explicit?

Are you willing to do full text search?
Are you also interested in looking for beginning of words?
Are you also interested in looking for "phrases" (a sequence of words)?

If you answered "yes" to all these questions, you should be interested in this map function:
  https://github.com/Hypertopic/Cassandre/blob/master/views/kwic/map.js

This view has to be simplified (to get rid of `speeches` and `corpora` management) but the idea is there:
indexing a "sliding window" of characters in the text, and calling them with `startkey="my keyword"&endkey="my keyword\ufff0"`.
With an index twice as big as this one, you could also do the same sliding window backwards and search for word endings.
However, if you really need to search inner parts of words, you would have to slide the window one character at a time (instead of one word at a time), which would result in an index ten times bigger... and, trust me, you probably don't want this.

But, well... All of these are already advanced MapReduce algorithms, I am not sure it is the best example to begin with CouchDB.

If you need less control over the full text indexing, you can also plug a full text indexer to do that for you:
    https://github.com/rnewson/couchdb-lucene


Regards,

Aurélien