How to create a CQL query using API that searches for an exact phrase

In the UI, if I want to search for the exact phrase “red line”, I just enclose it in quotes.

However, this does not seem to work from the REST API. No matter what I do, I get back all results that have either the word ‘red’ OR ‘line’ … and that’s way too many results.

I’ve tried:
?cql=text~%22red+line%22
?cql=text~%22red+AND+line%22
?cql=text~%27red+line%27
?cql=text~%27red+AND+line%27
?cql=text~red+AND+text~line

Hi,
Did you ever get an answer to this, I want to be able to do the same thing using REST Search API - but as you have mentioned, it AND’s all the words by default, and does not do an exact phrase match :frowning:

Sadly, no. No reply.

But the problem is that it OR’s all the words by default.

Hi @fbunting,

My apologies that it took a while for you to get an answer on this!

It looks like you encountered a bug with the text query CQL behavior that was fixed in late September 2020. Now if you try your query ?cql=text~%22red+line%22, you should only get results that contain both “red” and “line”. Also, for future reference, if you want to chain multiple CQL conditions with an AND, you can do that with syntax like ?cql=text~red+and+text~line

If you want to go back to red OR line, ?cql=text~red+or+text~line will work.

Hope that helps, let me know if you run into any more troubles with CQL.
Nora

1 Like