15.07.2016 Views

MARKLOGIC SERVER

Inside-MarkLogic-Server

Inside-MarkLogic-Server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

interest? Alerting gives you that. How about when an earthquake occurs in a certain city?<br />

Define the city as a geospatial query in the reverse index and check for matching latitude/<br />

longitude data when earthquakes occur.<br />

Without reverse query indexing, for each new document or set of documents, you'd<br />

have to loop over all of your queries to see which ones match. As the number of queries<br />

increases, this simplistic approach becomes increasingly inefficient.<br />

You can also use reverse queries for rule-based classification. MarkLogic includes an SVM<br />

(support vector machine) classifier. Details on the SVM classifier are beyond the scope<br />

of this book, but suffice to say it's based on document training sets and finding similarity<br />

between document term vectors. Reverse queries provide a rule-based alternative to<br />

training-based classifiers. You define each classification group as a cts:query. That<br />

query must be satisfied for membership. With reverse query, each new or modified<br />

document can be placed quickly into the right classification group or groups.<br />

Perhaps the most interesting and mind-bending use case for reverse queries is for<br />

matchmaking. You can match for carpools (driver/rider), employment (job/resume),<br />

medication (patient/drug), search security (document/user), love (man/woman or a<br />

mixed pool), or even battle (target/shooter). For matchmaking you represent each entity<br />

as a document. Within that document, you define the facts about the entity itself and<br />

that entity's preferences about other documents that should match it, serialized as a<br />

cts:query. With a reverse query and a forward query used in combination, you can<br />

do an efficient bi-directional match, finding pairs of entities that match each<br />

other's criteria.<br />

A REVERSE QUERY CARPOOL MATCH<br />

Let's use the carpool example to make the idea concrete. You have a driver, a nonsmoking<br />

woman driving from San Ramon to San Carlos, leaving at 8:00am, who listens<br />

to rock, pop, and hip-hop, and wants $10 for gas. She requires a female passenger<br />

within five miles of her start and end points. You have a passenger, a woman who will<br />

pay up to $20. Starting at "3001 Summit View Drive, San Ramon, CA 94582" and<br />

traveling to "400 Concourse Drive, Belmont, CA 94002." She requires a non-smoking<br />

car and won't listen to country music. A matchmaking query can match these two<br />

women to each other, as well as any other matches across potentially millions of people,<br />

in sub-second time.<br />

84

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

Saved successfully!

Ooh no, something went wrong!