docs: def filter_query(key, expression):
      """Filter documents with a key that satisfies an expression."""
      if (isinstance(expression, dict)
              and len(expression) == 1
              and list(expression.keys())[0].startswith('$')):
          compiled_expression = compile_query(expression)
      elif callable(expression):
          def _filter(index, expression=expression):
              result = [store_key
                        for value, store_keys in index.get_index().items()
                        if expression(value)
                        for store_key in store_keys]
              return result
          compiled_expression = _filter
      else:
          compiled_expression = expression
  
      def _get(query_function, key=key, expression=compiled_expression):
          """Get document key and check against expression."""
          return query_function(key, expression)
  
      return _get