Skip to content

Replacing Core Search

Matthew Boynes edited this page Aug 13, 2015 · 2 revisions

Once active, SearchPress will modify core's default front-end search to use Elasticsearch. This should be a seamless process, and you should only notice that something is different because your search is faster and the results more relevant.

What's happening behind the scenes (the technical explanation)

In short, SearchPress intercepts the main query, it takes the search terms and runs an Elasticsearch query to find posts matching the search. It grabs the IDs of the matching posts from Elasticsearch, then it returns back to the main query and modifies it to be a direct request for the found posts. In other words, SearchPress is using Elasticsearch to perform the search, but it's letting WordPress deliver the posts.

Default url arguments

SearchPress will automatically parse some query args and integrate them into its search.

Query Arg Usage
s The search query.
paged The current page of results.
year Restrict results to this (4-digit) year.
monthnum Restrict results to this month (1-12). Requires year to be set as well.
day Restrict results to this day (1-31). Requires year and monthnum to both be set as well.
post_type Restrict results to one or more post types. Core only allows a single post type to be set via URL, but SearchPress will correctly interpret a comma-delimited list of post types, e.g. ?post_type=post,page.
orderby Results ordering; can be "date" or "relevance".
order Results order; can be "asc" for ascending order or "desc" for descending order.
sp[f] A custom argument for SearchPress, which allows you to set an inclusive starting date for a range search. This should be in the format yyyy-mm-dd, e.g. 2015-07-01.
sp[t] A custom argument for SearchPress, which allows you to set an inclusive ending date for a range search. This should be in the format yyyy-mm-dd, e.g. 2015-07-01.

SearchPress will also correctly interpret the private query var posts_per_page, which is set in the WordPress admin (or overridden via code).