Extract query and add filtering

Hello, I am trying to add an extra filter on a query used for searching a listing.
I would like to be able to add a restriction on an attribute, regardless of the form.

What I wanted to do was

add_action(
	'hivepress/v1/models/listing/search',
	function($query,$fields) {
				
		$query->filter(
		[
			'pets'   => 'allowed',
		]);
			
	},0,2
);

but it is not working. What am I doing wrong?
Thanks a lot

If this attribute has checkbox type then please try this PHP snippet. Also, please change hp_pets in the code snippet on the hp_ + your attribute slug or field name

add_action(
	'hivepress/v1/models/listing/search',
	function($query,$fields) {
		$meta_query = array_filter( (array) $query->get( 'meta_query' ) );
		$meta_query['pets'] = [
			'key' => 'hp_pets',
			'type' => 'CHAR',
			'compare' => 'EXISTS',
		];
		$query->set( 'meta_query', $meta_query );
	},
	1000,
	2
);