Domanda

I am new to MarkLogic, and I'm trying to extract information from documents using the search API. My documents are in the below format.

<nitf>
<head>
<title>ABC</title>
</head>
...
...
</nitf>

I would like to show only the titles of the documents that match the search query in the results, i.e. the search API must return only titles of matching documents. I have gone through the documentation and tried a different things such as query options which was suggested by @ehennum , but to no effect. Any help on this would be great. Thanks!

È stato utile?

Soluzione

Krishna, it sounds like you don't want snippets at all, so you should turn off snippeting:

<search:transform-results apply="empty-snippet"/>

Then to get the title, use extract-metadata:

<search:extract-metadata>
  <search:qname elem-ns="" elem-name="title"/>
</search:extract-metadata>

Altri suggerimenti

As a footnote to Dave's good suggestion, MarkLogic 7 provides Query By Example as a simple interface to search. Please see:

http://docs.marklogic.com/REST/POST/v1/qbe

http://docs.marklogic.com/guide/search-dev/qbe#id_54044

The particular query would look something like the following:

<q:qbe xmlns:q="http://marklogic.com/appservices/querybyexample">
  <q:query>
    ... your query by example ...
  </q:query>
  <q:response>
    <q:snippet><q:none/></q:snippet>
    <q:extract><title/></q:extract>
  </q:response>
</q:qbe>

If I recall correctly, NITF doesn't use a namespace, but if it did, you'd have to qualify title with the prefix.

To expand on the fine answer from @dave-cassel, since MarkLogic version 8, the <search:extract-metadata> option is deprecated and you should use search:extract-document-data instead--lifted directly from the API docs:

<search:extract-document-data selected="include">
  <search:extract-path xmlns="">/userName</search:extract-path>
</search:extract-document-data>

More: https://docs.marklogic.com/search:search#opt-extract-document-data

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top