Search suggest functionality in marklogic

Viewed 22

Currently, I am using the dictionary file to get suggestions for the searched keyword. Instead of that, Is there any way to get suggestions from our loaded json document?

Or, Is there any way to ingest keywords from the loaded json document into our dictionary file?

1 Answers

You can use a custom dictionary with spell.suggest()

Suggests a list of spellings for a word. Returns a Sequence containing the most likely spellings for the specified word.

There is documentation about Custom Dictionaries in MarkLogic Server. And it describes how you can modify and update the dictionary

If you wanted to get suggestions using the document content as the source, then you can use search.suggest() and configure the suggestion-source for a particular lexicon.

This function returns a sequence of suggested text strings that match a wildcarded search for the $qtext input, ready for use in a user interface. Typically this is used for type-ahead applications to provide the user suggestions while entering terms in a search box.

On large databases, the performance of using a word lexicon for suggestions will probably be slower than using a value lexicon. This can be very application specific, and in some cases the performance might be good, but in general, value lexicons (range constraints) will perform much better than word lexicons (word constraints) with search.suggest. Therefore, MarkLogic recommends using value lexicons for suggestions, not word lexicons.

The performance of search.suggest is highly data-dependent. The best performing suggestion sources are value lexicons (range indexes) that use the codepoint collation. Performance is also impacted based on the number of matches, and it can help to design the interaction between search.suggest and the UI so that suggestions are given after a minimum of 3 characters are entered (that is, the lexicon match calls will have at least 3 characters). Again, this is quite data-dependent, so you should try it on a large data set with your own data.

You could leverage both of the functions in order to produce a fuzzy type-ahead driven from custom dictionary and document content. Using spell.suggest() with your custom dictionary to expand the list of terms that would then be used as inputs to search.suggest().

Related