Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to search through CouchDB documents for substring

Tags:

couchdb

CouchDB gives an opportunity to search values from startkey, for exact key-value pair etc But is there any way to search for substring in specified field?

The problem is like this. Our news database consists of about 40,000 news documents. Say, they have title, content and url fields. We want to find news documents which have "restaurant" in their title. Is there any way to do it?

View Collation wiki page tells nothing :( And it seems strange to me that there's no tool to handle this problem and all I can to do is just parsing JSON results with Python, PHP or smth else. In MySQL it's simply LOCATE() function..

like image 826
Dmitrii Sorin Avatar asked Dec 28 '22 04:12

Dmitrii Sorin


2 Answers

Use couchdb-lucene.

like image 198
Anand Chitipothu Avatar answered Feb 12 '23 11:02

Anand Chitipothu


Be careful here. Lucene is not always the best answer.

If your only searching one limited field and only searching for a word like restaurant then lucene which is really meant to tokenize large texts/documents can be way overkill, you can get the same effect by splitting the title.

function(doc){
         var stringarray = doc.title.split(" ");
         for(var idx in stringarray)
         emit(stringarray[idx],doc);

        }

Also Lucene and Couchdb do not support substring search, where the string is not in the beginning of a word.

like image 24
h1vpdata Avatar answered Feb 12 '23 11:02

h1vpdata