Perform an Empty Search with Sorting and Facets

Sometimes users don't want to enter a keyword but just browse using filters and facets. Indx supports this as long as you have at least one field set to facetable.

enableFacets is what makes an empty query legal. Without it, empty text is refused rather than treated as "match everything": the search returns 200 with no records and a reason of Search called with empty string and EnableFacets=false. Since a refusal and an honest no-match look alike apart from that reason, a browse page that forgets the flag shows an empty catalogue and no error. Read reason on every search and fold it in with a timeout: a populated reason means the query was refused, which is never the same thing as "found nothing".

You also need at least one facetable field. With facets enabled but nothing facetable, the empty query is served but comes back empty.

An empty search goes through all documents and ignores CoverageDepth settings. Empty queries typically take more time than queries with input text.

Without a SortBy field, results are returned in indexing order (the order documents were loaded). To get meaningful ordering, set at least one field to Sortable = true and specify it in the query.

csharp
query.Text = ""; // or null
query.SortBy = engine.GetField("Movie_Rating")!; // default descending, so 8.0 before 7.0
query.EnableFacets = true;