MarkLogic search: find all hits in a single document

87 Views Asked by At

I am trying to use the search:search function in MarkLogic to find all hits in a single XML document. So far, I can only get search:search to return one hit per document. The function cts:search returns multiple hits within a single document, but without the added features that search:search adds to the results. How do I set up the options to search:search to return all the hits in a single document?

To restrict the search to a single document, I am using the search:options:

declare variable $options :=
<options xmlns="http://marklogic.com/appservices/search">
  <additional-query>
    <cts:document-query xmlns:cts="http://marklogic.com/cts">
      <cts:uri>/foo/bar/baz/doc.xml</cts:uri>
    </cts:document-query>
  </additional-query>
</options>;

search:search("findme", $options)

My cts query looks like this:

declare namespace cts = "http://marklogic.com/cts";
cts:search(doc("/foo/bar/bax/doc.xml")//p, "findme")

If I do not add the xpath "//p", I get the entire document returned. And adding the xpath is not really acceptable, since text() is found in a quite a number of different elements.

Thanks for the help.

1

There are 1 best solutions below

0
Rob S. On

By default, you should actually only get one hit per document with cts:search and multiple snippets per doc with search:search. So I'd be interested to see your cts:search call. Perhaps you are using the $expression parameter?

As for modifying the snippets from search:search, you can refer to customizing snippets in the documentation to define a snippet transform to control the number of snippets per result. In particular, look at the <max-matches> and <per-match-tokens> options. There are some examples are here.