Enable SearchPress for REST API search endpoint
mslinnea opened this issue · comments
When SearchPress is active, it replaces the built in WordPress search. However, it doesn't replace search queries that happen via the REST API.
Example: https://alley.test/wp-json/wp/v2/posts?search=happy
Cause:
Searchpress checks if the query is the main query before proceeding.
https://github.com/alleyinteractive/searchpress/blob/master/lib/class-sp-integration.php#L188
The REST API doesn't set the main query, so this is always false.
My one and only concern with this is that API searches may originate from either the frontend or backend (admin area). Searches originating via the admin probably should not be set to use Elasticsearch (that's why ES Admin exists). Offhand, I'm not certain if we can discern between them out-of-the-box.
Beyond that, I would request that this be implemented as optional via a filter. The question then becomes if it's opt-in or opt-out, and I think that depends on the above note re:admin-originating requests.