Extending Search API
There's much more to the Search API, and you can extend it yourself by writing custom constraints. Custom constraints are useful if you want full control over how a term without a constraint prefix should be handled, want to provide relevance weightings to different constraints, want a constraint to look in multiple places for a match, or want features like implicit phrase boosting. Let's look at how we'd control a term without a constraint prefix.
By default, terms entered into search:search()
simply search all text nodes of
a document. If we want to control that behavior we can plug in a little
code. The following options node says for regular terms to call out to our
own search-options.xqy
library module to control the behavior. In it we
specify exactly where we want to look (i.e. not inside header values) and with
what relevance weightings.
The search-options.xqy
library is fairly complex, but it's a lot of
boilerplate. The so:myterm()
function extracts the simple token and converts
it to a complex cts:or-query
. It makes sure to use the options passed in on
the options node for things like case sensitivity. The important part of this
is the cts:or-query
definition that dictates where to look for matches and
with what relevance weightings.
I've installed the library for you. You can't modify it, but you can tweak
the search:search()
call.
The Search API
Conclusion
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.