What is a reverse query?


What is a reverse query?

  • 6 May, 2024
  • By Dave Cassel
  • No Comments

How do you know when your database has something new that would interest your users? How do you categorize incoming data? How do you know whose workflow to assign a new document to? With Progress MarkLogic, you use the reverse query feature. Let's take a look.

In a normal (forward) query, we define a set of criteria (our query) and ask the question, "What data do we have that matches this query?" The answer for MarkLogic will be a set of documents that match the criteria. (In a relational database, it will be a set of values from rows that match.) This is how we typically write queries.

Not surprisingly, we turn that around for a reverse query. In MarkLogic, we store queries in the database. We can then ask about a new document, "Which queries match this data?" We can then take whatever action we want based on the matching queries. Imagine your users running a complex search to find interesting content, then hitting a "Save" button for that query. Give them a checkbox to say "Alert me when new content matches this query." What better way to keep up with new research results, news, new policies, etc.?

Progress MarkLogic does this by serializing the query itself, including facet selections, word queries, and any other criteria that can be used in search. This serialized query is stored in a document along side other data -- part of the benefit of a flexible storage model. When new content gets loaded, we run a reverse query, and we immediately know which saved searches match.

This might sound a little like triggers. MarkLogic supports triggers too, but as with relational systems, they are address a different use case. Triggers fire when there is new, updated, or deleted data, but lack the granularity of a reverse query. A trigger is fired when a particular document (or relational row) changes; a reverse query can fire for any supported query.

Alerting is a powerful feature driven by reverse queries, but there are other use cases as well. With this approach we can categorize content or assign it to particular people in a workflow.

How could your application benefit by looking at new content as it comes in?

Share this post:

How do you know when your database has something new that would interest your users? How do you categorize incoming...

4V Services works with development teams to boost their knowledge and capabilities. Contact us today to talk about how we can help you succeed!

5 2 votes
Article Rating
Notify of
Inline Feedbacks
View all comments

Looking Forward to Building a Partnership!

Let's discuss how we can help your organization