no Suggestions for word constraints

Viewed 63

In my search:suggest call I specify a word prefix constraint on a element. For some reason I am not getting suggestions for that prefix constraint search:

This code illustrates my problem:

let $doc := 
<doc>
  <title>Show me some suggestions!</title>
</doc>

return xdmp:document-insert('so.xml', $doc);

import module namespace search = "http://marklogic.com/appservices/search"
    at "/MarkLogic/appservices/search/search.xqy";

search:suggest('title:', 
  <options xmlns="http://marklogic.com/appservices/search">
    <constraint name="title">
      <word collation="http://marklogic.com/collation/en">
        <element name="title" />
      </word>
    </constraint>

    <default-suggestion-source>
      <word-lexicon collation="http://marklogic.com/collation/en"/>
    </default-suggestion-source>
  </options>
)

This does not result in any suggestions. Only after adding the following suggestions-source, I get the expected suggestions:

<suggestion-source ref="title">
   <word collation="http://marklogic.com/collation/en">
      <element name="title"/>
   </word>
</suggestion-source>

This does not seem to be the same with range or collection constraints, suggestions work out of the box and without a suggestion-source.

Is there a reason why suggestions are not shown for word constraints, e.g. performance? Is this behaviour documented somewhere?

Using MarkLogic 9.0-8.

1 Answers

If you have created a word lexicon for a specific JSON property or element, the options should be able to refer to a constraint this way:

<default-suggestion-source ref="title"/>

or identify the word lexicon inline this way:

<default-suggestion-source>
  <word collation="http://marklogic.com/collation/en">
    <element name="title" />
  </word>
</default-suggestion-source>

The word-lexicon query option specifies the database-wide word lexicon. If the database-wide word lexicon has been enabled for the database, the word-lexicon element should work -- though it is not recommended (unless the database is very small).

For more information, see:

http://docs.marklogic.com/guide/search-dev/search-api#id_89118

http://docs.marklogic.com/guide/search-dev/appendixa#id_35361

Hoping that helps,

Related