alleyinteractive / searchpress

Elasticsearch integration for WordPress.
82 stars 12 forks source link

Enable SearchPress for REST API search endpoint #113

Open mslinnea opened 4 years ago

mslinnea commented 4 years ago

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.

mboynes commented 4 years ago

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.