neighbourhoodie-nnh-logo

Full-text Search and Faceted Querying with CouchDB posted Wednesday, November 27, 2024 by The Neighbourhoodie CouchDB Team

CouchDB stores your JSON data naturally in documents. It also gives you multiple mechanisms for querying that data:

  • The available-by-default _all_docs and _changes endpoints.
  • JavaScript and Erlang-based MapReduce Views.
  • Mango Queries.

All of these mechanisms have different strengths and make different tradeoffs, but overall, they allow you to query your documents in a single dimension, that is, you can get all documents, sorted by last name, or by birthday, or whatever other field you have.

MapReduce views allow you to do computations on top of this single dimension, for example allowing you to ask “how many people are there with the last name ‘Taylor’”, or “how many people have their birthday in January”.

Mango Queries add the ability to be more specific in terms of what values your queried fields can have, with expressions that span multiple AND and OR clauses, like “show me all people with last name ‘Taylor’ and first name ‘Breonna’ that was born in 1993”.

However, Mango Queries have some limitations in terms of the flexibility of combining those clauses. That means that there are yet more queries that developers would like to be able to send to CouchDB, that can’t be answered with any of the existing mechanisms.

This is where Nouveau comes in. It is a fourth method of querying your data in CouchDB, and it is based on the immensely popular Lucene search project.

Lucene is famous for its comprehensive and high-performance search capabilities. With Nouveau, you can run full-text search queries across all your documents, like in any other search engine. You can search for parts of words, and flexible character patterns. Lucene’s search syntax is very extensive.

In addition to full-text search, Lucene also supports even more flexible queries than Mango, with support for joins, facets, custom grouping logic, completing all query-needs for CouchDB. We’ve written a comprehensive guide to Nouveau that covers installation and set up, usage and the performance advantages you can enjoy with Nouveau.

You’ll be hard pressed to find a type of query that can’t be expressed in any of the above mechanisms.

« Back to the blog post overview