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.

Nothing typed: the whole list, with its filters and counts

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 the candidate bound (Candidates). 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.

On the Indx server the dataset's boost and bury rules order an empty search before the sort field: a campaign rule puts its records first, sorted among themselves. That suits a landing page. When the visitor picks the order ("Highest rated"), add "ranking": { "boostRules": false } and the list is by the field alone; bury rules still apply unless you also send "buryRules": false. @indxsearch/intrface does this for a sort the visitor picks.

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