Search code examples
marklogic

Confused with search:suggest


I'm not able to provided this simple autocompletion feature with the help of the search:suggest function.

Based on the Oscars corpus from Marklogic Demo data, I try to provide a suggest query which was for instance able to return "Robert Loggia" as an answer even if the user is currently writing "Robert Lo" or "Loggia Rob" or even "L Rob".

Currently, I'm only able to return "Robert Loggia" amongst some of his peers with this simple query :

let $options := 
<options xmlns="http://marklogic.com/appservices/search">
  <default-suggestion-source>
    <range type="xs:string">
      <element ns="http://marklogic.com/wikipedia" name="name" />
    </range>
  </default-suggestion-source>
</options>
return search:suggest("Rob",$options)

But as soon as I'm writing a two words phrase, I'm not sure to understand how to write that, because none of the answer is correct with what I'm waiting. For instance :

search:suggest("Robert Lo",$options)

or

search:suggest(("Robert", "Lo"),$options)

Is it due to missing option, indexes misconfiguration or a misused feature ?

Thanks For Help


Solution

  • It's grammar-aware.

    You need to add quotes around the phrase if you want to get suggestions on the phrase, otherwise it treats the tokens separately. Try the following:

    search:suggest('"Robert Lo"',$options)