Use http://docs.marklogic.com/search:search and supply it with the <searchable-expression>
option.
The search:search
function already implements what you want. Under the hood it calls cts:search
and supplies the searchable-expression using xdmp:value
. You could do that to, but search:search
has already been written and tested.
In passing, using path-based searchable expressions with cts:search
is something of a trap for the unwary. In most cases it is better to use collection()
as the first argument to cts:search
, matching the entire database. Then use a cts:query
for the second parameter, to match the documents you are interested in.
But what about //p
? It's important to understand that MarkLogic indexes fragments, not elements. By default, fragments are documents. You can change that: you can even fragment at the //p
level. But in most cases it's a bad idea. You're probably better off using cts:search
to match documents, and cts:highlight
to find matches in paragraphs. The search:search
function supports that, too.