Search code examples
searchmarklogiccode-snippets

How can I search by specifying a specific node with MarkLogic and get results with a snippet?


I want to do the following for documents registered in the MarkLogic database.

  1. Before searching, associate a search word with its associated document
  2. Search only documents associated with search words and obtain results with snippet

If you want to get a snippet as a search result, I'd like to use Search API search: search or search: resolve functions. However, unlike the cts: search function, these functions can not specify a node as an argument, so it seems that you can not search only for a specific node (document).

cts:search:

cts:search(
    $expression as node()*,
    $query as cts:query?,
    [$options as (cts:order|xs:string)*],
    [$quality-weight as xs:double?],
    [$forest-ids as xs:unsignedLong*]
) as node()*

search:resolve:

search:resolve(
    $query as element(),
    [$options as element(search:options)?],
    [$start as xs:unsignedLong?],
    [$page-length as xs:unsignedLong?]
) as element(search:response)

Please let me know if you are searching only for specific documents (nodes) and knowing how to obtain search results as snippets.


Solution

  • I think you are looking for <searchable-expression> that you can put in the <search:options>. See also:

    HTH!