Understanding operation count

I read the docs, but don’t fully understand operation count, and my operations have always been higher than anticipated, so I’d like to understand.

For simplicity, assume: 1) Using react-instantsearch, 2) “search as you type” is disabled so the user must press enter to search, 3) using only 1 index.

  1. On the initial page load with no query or faceting applied, I have multiple MenuSelect and RefinementLists on the page, these by default show a count of items for each of their values. Do each of these elements cause an operation, just to be loaded on the page? I.e. If there are two MenuSelects and one RefinementList, it’s 3 operations to load the page? (Or actually 4 given the initial default hits are loaded.)

  2. Assume my results are currently restricted by 3 facets (isFoo, isBar, isBaz) and I refine by a 4th facet (isBat), does clicking “isBat” cause 1 or 4 more new operations?

  3. Using a range, if I reset a range to its extremes, and my searchState will still contain the name of my range, such as searchState.range.mySliderName.min = undefined and searchState.range.mySliderName.max = undefined. Am I charged an operation because mySliderName still exists on the range property? Should I manually delete mySliderName or even range off of the searchState, in order to reduce my operation count?

  4. (non-React question) If I search (via https://www.algolia.com/doc/api-reference/api-methods/search) with a limit of 100 and 100 results are returned, is this one operation or 100? I believe it’s just 1.

  1. Just loading these elements does not result in search operations. Loading the hits on an empty search counts as a search operation, though.

  2. If you use the disjunctive faceting feature in your search and facet selection, the number of operations for each query will depend on the number of disjunctive facets you use. Therefore indeed, if you are using disjunctive search, selecting isBaz in addition to 3 previously selected filters will result in 4 new operations. This is necessary to get the correct facet counts.

  3. Each time you reset a rangeSlider you are in effect adding in additional filters. Each time you send in a new parameter this is another search operation. If you are not altering the the min or max, just having range or range.mySliderName on your searchstate should not increase your search operations.

  4. Using the search method once counts as 1 operation regardless of the number of hits you get.

This is a great response! Thank you.

A follow up to #2:

  • if I currently have 3 separate toggleRefinements, there is no efficiency benefit to switching them all to be parts of a RefinementList using “or”, because both scenarios will cause 4 (facet count queries) + 1 (data query) additional queries when a 4th item of the same type is refined? Or maybe the RefinementList is more efficient b/c refining by the 4th item on a refinement list is only 2 queries (1 for data, 1 for new facet count).
  • is it possible to disable facet count queries on React components to reduce query usage? other tips?
  • wait…if 1 query is needed to show the facet count…shouldn’t the initial page load use 1 query for hits + 1 query for every element (toggle, input, etc) that contains a facet count for its values?

(That would explain why I have so many queries during my testing, visitors will basically be using them 5-10 at a time when they are refined, or even just loading pages with many elements showing facet counts, and even worse if “search as you type” is enabled when refinements are already selected.)

It’d be cool if there were a react dev logging utility to plug into my onSearchStateChange calllback where I could perform a search, or load a page, and see a list and count of queries issued, to know how to make it more efficient.

Hey @jbb!

  • ​Three toggleRefinements in the same attribute isn’t really comparable to a Refinement List of that attribute because ToggleRefinements aren’t built in such a way that multiple of them are meant to be used for the same refinement (see what I mean here).
  • While you can set a particular attribute for faceting to be filterOnly (i.e. never calculate facet counts), our faceting IS components are designed to work with attributes for faceting that do include facet counts and they will break if you try to use them with a filterOnly attribute. That said, you could try to build custom UI components that do not rely on facetCounts if you’d really like to get the query usage down.
  • The additional facet counts thing really only applies to disjunctive faceting because of the “OR” involved here. (We need to see the facet counts for each individual part of the query.) Therefore, when you do an initial page load, only one query is fired to get the hits / facet counts for that single set of parameters (presumably an empty query string). Once you start adding in disjunctive faceting, that’s when there are multiple queries involved.

Hope this helps to clarify! A react dev logging utility to track searches is a neat idea – I’ll pass it on to the team!​​