<?php
declare( strict_types=1 );

namespace FiboFilters\Integrations\Plugins;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class Relevanssi
 *
 * Plugin Name: Relevanssi
 * Plugin URI: https://wordpress.org/plugins/relevanssi/
 * Tested versions: 4.24.6
 */
class Relevanssi extends AbstractPlugin {
	public function init(): void {
		add_filter( 'relevanssi_search_ok', [ $this, 'relevanssi_search_ok' ], 10, 2 );
	}

	/**
	 * Allowing Relevanssi to interfere with the query related to retrieving base product IDs
	 *
	 * @param boolean   $search_ok Whether Relevanssi should interfere with the query.
	 * @param \WP_Query $query The WP_Query object.
	 */
	public function relevanssi_search_ok( $search_ok, $query ): bool {
		if (
			is_a( $query, 'WP_Query' ) &&
			$query->get( 'fibofilters_get_base_product_ids' ) &&
			! empty( $query->get( 's' ) )
		) {
			$search_ok = true;
		}

		return (bool) $search_ok;
	}
}
