问题
I want to find the similar location names using couchbase server. i created an index as follows
function (doc, meta) {
emit(doc.loc_name, doc);
}
this is how i query data
http://IP Address:8092/dev-locations/_design/dev_test_view/_view/searchByLocationName?full_set=true&inclusive_end=true&stale=false&connection_timeout=60000&key=%22Joh%22
But this will return only if the exact match found. What i am looking for is when i send the key joh
, it should return johenaskirchen
and johenasberg
(same as our LIKE in MySQL)
Any help will be highly appreciated.
Note : I already tried N1QL and i am looking for ways to implement this without N1QL
回答1:
the key
parameter is an exact match. What you want is a combination of startKey
and endKey
:
?startkey=%22joh%22&endkey=%22joh\uefff%22
The \uefff
is a trick, this unicode character can be seen as "the biggest character" so it ensures that a key like johzzzzzz
will still be considered under the upper bound of joh\uefff
(endkey
is inclusive).
来源:https://stackoverflow.com/questions/31268624/find-similar-names-using-couchbase-server-3-0-and-port-8092