1

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!

Dixit Singla
  • 2,540
  • 3
  • 24
  • 39
  • Your example reads "`pubTitle:''test pub''`" (you use doubled single quotes to wrap your search phrase, but instead I think it should be `pubTitle:'test pub'`. Typo or deliberate? – grtjn Mar 10 '17 at 09:10
  • It is with double quotes ( "pubTitle:''test pub''") I am passing it as the first parameter of search:search, edited the question also – Dixit Singla Mar 10 '17 at 13:55
  • I was talking about the quotes around `test pub`.. – grtjn Mar 10 '17 at 14:33
  • Yes there are two double single quotes... If there is only one single quote then there is no problem search api will form the cts query as expected... – Dixit Singla Mar 10 '17 at 14:36
  • @grtjn If you understand the problem, please help. – Dixit Singla Mar 16 '17 at 04:59
  • Unfortunately, your description and comments are not very clear to me. Make sure you use quotes carefully. I see no need for doubling single quotes. Also, unclear why you used single quote for quotation in the search options. Why not use the default double quotes for quoting? – grtjn Mar 16 '17 at 08:00
  • @grtjn I have updated my question. Please let me know if you need more detail. – Dixit Singla Mar 16 '17 at 09:31
  • That explains the single quotes, now I fully understand your problem.. – grtjn Mar 16 '17 at 19:12

1 Answers1

1

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 &quot; 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!

grtjn
  • 20,254
  • 1
  • 24
  • 35