Is there a way to find CouchDB documents for substring

CouchDB provides the ability to search for values ​​from startkey, for an exact key-value pair, etc. But is there a way to search for a substring in a specified field?

The problem is 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 that have a “restaurant” in the title . Is there any way to do this?

Viewing the sorting wiki page says nothing :( And it seems strange to me that there is no tool to solve this problem, and all I can do is simply analyze the JSON results using Python, PHP or smth else. In MySQL, it's just a LOCATE function ( )

+4
source share
2 answers

Be careful. Lucene is not always the best answer.

If your only search in one limited field and search only for a word, such as a restaurant, then lucene, which is really intended to mean large texts / documents, may be excessive, 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 at the beginning of the word.

+4
source
+6
source

All Articles