Company
Date Published
Author
MongoDB
Word count
3345
Language
English
Hacker News points
None

Summary

Faceted search functionality can be implemented in MongoDB without requiring the use of external search engines. For this example, let's say we have three facets on which we wish to search – Subject, Publisher and Language – and consider how to search efficiently, and how to generate the faceted navigation meta-data to present to the user. The performance characteristics of different approaches to implementing faceted search in MongoDB are discussed, including schema #1 where all facet types and values are stored in subdocuments in an array, schema #2 where all facet types and values are concatenated into a single string value, and schema #3 where each facet is associated with an array of tags. The benefits of these different approaches include smaller index sizes for schema #3, but the need to perform more aggregation queries when using this schema. An additional approach is discussed which involves pre-computing faceted navigation meta-data and storing it in a separate collection, which can be updated quickly by specifying that the map-reduce job operate only on the recently updated items. Third-party tools such as Solr and ElasticSearch are also available for providing faceted search capabilities.