Solutions

Stay on top of everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

Learn

Stay on top of everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

Community

Stay on top of everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

Company

Stay on top of everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

Understanding search results

As you've seen, you have a choice between XML and JSON when it comes to search results. Whichever format you choose, the results provide the data needed to construct a search application. For example, you could use the following excerpted JSON data:

to construct a search results pagination widget (as on this website's search results page):

Machine generated alternative text: Page 1 of 9»

Then, you would iterate through each of the objects in the results array:

to produce the contents of your search results page:

shows a visual representation of a few search results as they would be presented to the user

In addition to the document's score, URI, etc., each result includes a matches array which contains one object for each matching area of text:

Machine generated alternative text: Search Results Pagep__1Iof9 Results 1—lo of 87 for range Index matches array ‘ ad APIs ._.Jno matter what the database size. As part of loading a I document, run-text indexes are created making arbitrary searches fast. Searches automatically use matches array O Mministrato?s Guide 4— “ I1nex confiuration as described in 1.IText IndexingI..ange indexes, as described iniIement (ana Awl btx Rdrryé indexes arid LeWins

And within each match is a match-text array, which is a list of strings which may or may not be highlighted (highlighted when they contain the actual matching term or terms):

Machine generated alternative text: Search Results  Results 1—lo of 87 for range Index Search Developer’s Guide ILexicon an Ranøe I e4.ased APIsL no matter what the database size. As part of loading a documen, ¡ created making arbitrary searches fast. Searches automatically use the match-text array Mmlnlstrator’s Guide Index configuration, as described in ...Text Indexing.. .Range indexes, as described in ...Element and Attribute Range Indexes and Lexicons

The XML version of the results is generally isomorphic to the JSON version. In place of the results, matches, and match-text arrays are the <search:result>, <search:snippet>/<search:match>, and <search:highlight> elements, respectively:

The above excerpt of XML results corresponds to the same data as the JSON results we saw.

Basic Search

Custom search

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.

Comments

The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.
  • In each result fragment shown above, there is a readable document title ("Search Developer's Guide"; "Administrator's Guide"). I can't find this in the result XML. Where does it come from?
    • Matthijs, the screen shots above are taken from an application that uses a custom REST API options node, discussed on the next page of this tutorial. In particular, you would add extract-metadata, specifying the field or element where the title exists. Doing so adds that field/element to each result. http://docs.marklogic.com/guide/rest-dev/appendixa#id_41417