Skip to main content
Since May 1st, 2024, Apple requires all iOS apps to include a privacy manifest. For more details, see Privacy Manifest.
By default, InstantSearch sends an initial request to Algolia’s servers with an empty query. This connection helps speed up later requests. However, sometimes you don’t want to perform more network calls than are necessary. For example, you may want to limit the number of search requests and reduce your overall Algolia usage. This guide helps you build a UI that prevents this initial request.

Set Searcher shouldTriggerSearchForQuery property

All the Searcher implementations such as HitsSearcher and FacetSearcher provide the shouldTriggerSearchForQuery closure which defines the boolean condition for triggering a search operation. By default has a nil value so the search will be triggered on each search() function call. The closure blocking searches for empty queries should look as follows:
Swift
let searcher = SingleIndexSearcher(appID: "ALGOLIA_APPLICATION_ID", 
                                   apiKey: "ALGOLIA_SEARCH_API_KEY", 
                                   indexName: "search_index_name")
searcher.shouldTriggerSearchForQuery = {
  return $0.query.query != ""
}
⌘I