I am using search:search
API.
In the search options grammar
, I have used quotation as "'
"
<quotation>'</quotation>
Now if the search string contains any single quote it will create a wrong cts:query
.
for example : "pubTitle:''test pub''"
For pubTitle
I have defined a constraint of element-word-query
.
But because of single quote '
, it's forming cts-word
queries
Update:
I have an XML file as given below
<root>
<pubTitle>'test''pu'b'</pubTitle>
<firstPage>12</firstPage>
<lastPage>45</lastPage>
</root>
Constraint defined :
<constraint name="pubTitle">
<value>
<element ns="" name="pubTitle"/>
</value>
</constraint>
Now I want to search for document with text 'test''pu'b'
in pubTitle element.
What would be my search query? (search:search
first parameter)
Help!
The update helped clear things up. You have content with single quotes.
More precisely, you want to search on a title containing single quotes, whitespace, and maybe even interpunction. Doing a value search makes sense, but the search string that you pass in into search:search
gets parsed. If you don't wrap search values or phrases in quotes, the parser will think that the value ends at the next whitespace. If you would not have changed the <quotation>
option, the parser would have stopped after ''test
(in the initial example you gave).
Changing <quotation>
to single quote made things worse, because your search value contains single quotes as well, and the parser will confuse them. I would not be surprised if search:search
ended up searching test
and pub
in full-text, which is the default behavior.
The double quote quotation is a bit tricky too, if you want to invoke search:search
manually. You need double quotes to wrap the search value, but also to define the entire search string. You could potentially escape inner double quotes by doubling them, writing them as "
entity, but you can also use a temporary xml fragment. Something like this:
xquery version "1.0-ml";
xdmp:document-insert("/test.xml", <root>
<pubTitle>'test'' pu'b'</pubTitle>
<firstPage>12</firstPage>
<lastPage>45</lastPage>
</root>)
;
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
let $searchText := <txt>'test'' pu'b'</txt>/concat('"', ., '"')
return
search:search(
"pubTitle:" || $searchText,
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="pubTitle">
<value>
<element ns="" name="pubTitle"/>
</value>
</constraint>
</options>
)
I hope this does the trick for you!