Web / Apache Lucene Interview questions
How does faceting work conceptually in Lucene?
Faceting answers "how many results fall into each category" alongside a normal search - like showing "Electronics (42), Books (17)" next to a product search. Lucene's facet module supports this without scanning every matching document at query time.
The typical approach uses a SortedSetDocValuesFacetField or a separate taxonomy index maintained alongside the main index. At index time, facet values are recorded per document; at query time, a FacetsCollector runs alongside the normal search collector, counting how many matching documents fall under each facet value using the pre-built structures rather than re-reading stored fields.
The taxonomy-based approach in particular supports hierarchical facets (Category > Subcategory) efficiently, since the taxonomy index stores parent-child relationships once rather than duplicating the full path per document.
More Related questions...