Api search:suggest is used to return suggestions that match a wildcard string.
syntax :-
search:suggest(
qtext as xs:string+
[options as element(opt:options)?]
[limit as xs:unsignedInt?]
[cursor-position as xs:unsignedInt?]
[focus as xs:positiveInteger?]
) as xs:string*
Keyword Suggestion in Marklogic can be used in two ways.
1) Query suggestions - By Async call to search:suggest for each key pressed in the textbox. This would fill the combo box with the suggested keywords to select as you see in Google or YouTube.
2) You may also go for:suggested words – you search your keywords and along with the search results you see some suggestions.
you can define your suggestion source as an existing element
Configure default-suggestion-source option for the suggestions.
<default-suggestion-source>
<samplecollection/>
</default-suggestion-source>
samplecollection can be existing named constraint, value, word or range element/attribute.
for eg.
Range element
<default-suggestion-source>
<range type="xs:date">
<element ns="samplenamespace" name="book"/>
<attribute ns="" name="publishDate"/>
</range>
</default-suggestion-source>
Word lexicon
<default-suggestion-source>
<word>
<field name="bookdata"/>
</word>
</default-suggestion-source>
If default-suggestion-source element is empty then the constraint or operator(if specified) in the options will be considered by default else it would return empty sequence.

No comments:
Post a Comment