15.07.2016 Views

MARKLOGIC SERVER

Inside-MarkLogic-Server

Inside-MarkLogic-Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

An Advanced Trick<br />

If you use the coordinate system "raw" in the API calls, MarkLogic treats the world as flat (as well as infinite)<br />

and compares points simplistically without the complex great circle ellipsoid math. This comes in handy<br />

if you ever want a two-value range index to represent something other than geography, such as a medical<br />

patient's height and weight. Assume height represented as longitude (x-axis) and weight as latitude (y-axis).<br />

If the data were laid out as a chart, the results from a large set of patients would look like a scatter plot.<br />

Using MarkLogic's geospatial calls you can draw arbitrary polygons around the portions of the chart that are<br />

meaningful—such as which patients should be considered normal, overweight, or underweight according to<br />

different statistical measures—and use those regions as query constraints. The trick works for any data series<br />

with two values where it makes sense to think of the data as a scatter plot and limit results by point, box,<br />

circle, or polygon.<br />

THE REVERSE INDEX<br />

All of the indexing strategies we've discussed up to this point execute what you might<br />

call forward queries, where you start with a query and find the set of matching documents.<br />

A reverse query does the opposite: you start with a document and find all of the matching<br />

queries (the set of stored queries that if executed would match this document).<br />

Programmatically, you start by storing serialized representations of queries within<br />

MarkLogic. You can store them as simple documents or as elements within larger<br />

documents. For convenience, any cts:query object automatically serializes as XML<br />

when placed in an XML context. This XQuery:<br />

{<br />

cts:and-query((<br />

cts:word-query("dog"),<br />

cts:element-word-query(xs:QName("name"), "Champ"),<br />

cts:element-value-query(xs:QName("gender"), "female"))<br />

)<br />

}<br />

82

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!