CouchDB Lucene How to URL Encode Query containing Minus (-)

351 Views Asked by At

I'd like to query text containing a minus (-) Sign, e.g.

foo-bar 

with a couchdb lucene fulltext query. Following lucene rules I'd have to escape the minus, resulting in

foo\-bar

Last I'd have to urlencode the backslash resulting in

foo%5C-bar

So the complete url would be:

http://127.0.0.1:5984/_fti/local/db/_design/foo/by_subject?q=foo%5C-bar

Neither works. The result is always split in two phrases

"q":"default:foo default:bar"

Leading to documents containing only foo or bar being found also.

Thanks for your help!

1

There are 1 best solutions below

1
On BEST ANSWER

Escaping the "-" isn't really what you need. The problem you are running into is that your analyzer tokenizes on the "-", so you are really searching for two different terms. You need to search for a phrase, instead. To search a phrase, just wrap it in quotes: "foo-bar"

or

http://127.0.0.1:5984/_fti/local/db/_design/foo/by_subject?q=%22foo-bar%22