1

I want to search marklogic for term that start with double quotes. i am using search-suggest.

term that i am searching is '"Independent'. When executed successfully, query should suggest multiple options with one option that is '"Independent party'. But its not returning any suggestion. I can see that search-suggest is not finding term that start with double quote. Please suggest how can i fix it.

code is shared below.

let $options:=<options xmlns="http://marklogic.com/appservices/search">
<additional-query>
 <cts:and-query xmlns:cts="http://marklogic.com/cts">
  <cts:collection-query>
   <cts:uri>myCollection</cts:uri>
  </cts:collection-query>
  <cts:or-query>
   <cts:collection-query>
     <cts:uri>anotherCollection</cts:uri>
    </cts:collection-query>
  </cts:or-query>
 </cts:and-query>
</additional-query>
<term>
 <term-option>case-insensitive</term-option>
 <term-option>punctuation-sensitive</term-option>
 <empty apply="all-results">
 </empty>
</term>
<constraint name="myTargetItem">
 <range collation="http://marklogic.com/collation/codepoint" type="xs:string" facet="false">
 <element ns="---" name="targetItem">
</element>
</range>
</constraint>
</options>


let $searchTerm := '"Independent'
let $searchTerm := concat('"*',$searchTerm )
let $searchTerm :=  concat("myTargetItem", ':', $searchTerm )
return search:suggest($searchTerm , $options,20)

Actual Result EMPTY

Expected myTargetItem:""Independent"

nimTas
  • 11
  • 5
  • Are you sure your additional query is correct? You may want to try removing that element completely and then testing it. – Rob S. Jul 11 '19 at 14:04
  • Yes @RobS.additional query is correct. its narrowing down search to my collections. probelm is that how can i search a term that start with double quote? – nimTas Jul 11 '19 at 14:11

1 Answers1

1

Give this a try:

let $options:=
<options xmlns="http://marklogic.com/appservices/search">
<additional-query>
 <cts:and-query xmlns:cts="http://marklogic.com/cts">
  <cts:collection-query>
   <cts:uri>myCollection</cts:uri>
  </cts:collection-query>
  <cts:or-query>
   <cts:collection-query>
     <cts:uri>anotherCollection</cts:uri>
    </cts:collection-query>
  </cts:or-query>
 </cts:and-query>
</additional-query>
<default-suggestion-source>
  <range collation="http://marklogic.com/collation/codepoint" type="xs:string" 
    facet="false">
   <element ns="" name="targetItem"/>
  </range>
  <suggestion-option>case-insensitive</suggestion-option>
  <suggestion-option>punctuation-sensitive</suggestion-option>
</default-suggestion-source>
</options>


let $searchTerm := '"Independent'
let $searchTerm := concat('"*',$searchTerm )
let $searchTerm :=  concat("myTargetItem", ':', $searchTerm )
return search:suggest($searchTerm , $options,20)
Rob S.
  • 3,599
  • 6
  • 30
  • 39
  • 1
    Thanks for sharing. i had to change options in order to execute it without error.i had to remove and added the term element as i already had originally. so, t executes and give result. it return me other three possible options that start with word 'Independent' but result doesn't include the option that start with double quote. Please guide. – nimTas Jul 12 '19 at 08:47
  • i think i need to manipulate search grammar. if you see, ' "Independent ', this double quote doesn't get treated as double quote. instead, search ignores it or consider it a phrase search. any comment about it? – nimTas Jul 12 '19 at 11:32
  • While going through marklogic docs, i came to know that "You cannot specify a search that includes quotation character". Reference URL is https://docs.marklogic.com/guide/search-dev/appendixa#id_41181. so, i think thats the final answer to my query then :| – nimTas Jul 12 '19 at 11:56
  • @nimTas Not sure offhand but you may be able to add true and see what's being run under the hood in your return. I'm very interested in this and will try to reproduce it if I have some time soon. – Rob S. Jul 12 '19 at 13:39
  • @nimTas That link also says " For example, in the DEFAULT grammar, you cannot search for a double quote (") because this is the quotation character." I emphasized the word default. So you may want to try adding # to your search options. – Rob S. Jul 12 '19 at 13:42
  • yes @RobS. You are right. As per docs, we could have customize default grammar. But its deprecated now. still, there are some third party services available. but i don't think that will be a safe approach. Reference url is "https://docs.marklogic.com/guide/relnotes/chap5#id_38143". But may be i will try to customize, just to see how it will go. Then will share my experience – nimTas Jul 13 '19 at 14:12