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.