I want to perform a LIKE-condition (SQL syntax) in CouchDB. How can this be done? The LIKE-condition will be used to perform auto complete in the browser.
I want to write “co” in the input field and get the results Coffee, Couch, CouchDB ect.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is very easy to search for letters at the beginning of a string. You just need a view that emits the string you want to search for as the key. Assuming the user input is stored in a variable
q, you then call that view with the parametersstartkey=qandendkey=q+"\ufff0".The trick here is to append the highest possible Unicode character to the search string. In the sort order, this string comes after anything else starting with
q. (This is much easier to implement than the solution suggested by @titanoboa, where you need to “increment” the last letter of the user input.)If you also want to be able to find words in the middle of a string (e.g. “The Colbert Report” when typing “co”), you could use a view like this:
Of course this is only advisable for short strings. For searching in longer texts you should look into a full-text search add-on like couchdb-lucene.