PHP Class EP_API

Mostra file Open project: 10up/elasticpress Class Usage Examples

Public Methods

Method Description
__construct ( ) Placeholder method
bulk_index_posts ( $body ) : array | object | WP_Error Decode the bulk index response
create_network_alias ( array $indexes ) : array | boolean Create the network alias from an array of indexes
delete_index ( string $index_name = null ) : array | boolean Delete the current index or delete the index passed by name
delete_network_alias ( ) : boolean | array Delete the network index alias
delete_post ( integer $post_id, boolean $blocking = true ) : boolean Delete a post from the ES server given a site ID and a host site ID which is used to determine the index to delete from.
elasticpress_enabled ( $query ) : boolean Check to see if we should allow elasticpress to override this query
elasticsearch_can_connect ( ) : boolean This function checks if we can connect to Elasticsearch
factory ( ) : EP_API Return singleton instance of class
format_args ( array $args ) : array Format WP query args for ES
format_request_headers ( ) : array Add appropriate request headers
get_cluster_status ( ) : array Get cluster status
get_elasticsearch_version ( ) : string Get Elasticsearch version
get_index_status ( integer $blog_id = null ) : array Get index status
get_plugins ( ) : array Get Elasticsearch plugins
get_post ( integer $post_id ) : boolean Get a post from the index
get_query_log ( ) : array Return queries for debugging
get_search_status ( integer $blog_id = null ) : array Retrieves search stats from Elasticsearch.
get_sites ( integer $limit ) : mixed | void Wrapper function for get_sites - allows us to have one central place for the ep_indexable_sites filter
index_exists ( null $index_name = null ) : boolean Checks if index exists by index name, returns true or false
index_post ( array $post, boolean $blocking = true ) : array | boolean | mixed Index a post under a given site index or the global index ($site_id = 0)
is_empty_query ( array $response ) : boolean Check if a response array contains results or not
parse_api_response ( object $response ) : array Parse response from Elasticsearch
parse_site_id ( string $index_name ) : integer Pull the site id from the index name
prepare_meta ( object $post ) : array Prepare post meta to send to ES
prepare_meta_types ( array $post_meta ) : array Prepare post meta type values to send to ES
prepare_meta_value_types ( mixed $meta_value ) : array Prepare meta types for meta value
prepare_post ( integer $post_id ) : boolean | array Prepare a post for syncing
put_mapping ( ) : array | boolean | mixed Send mapping to ES
query ( array $args, array $query_args, string $scope = 'current' ) : array Search for posts under a specific site index or the global index ($site_id = 0).
refresh_index ( ) : boolean Refresh the current index
remote_request ( string $path, array $args = [], array $query_args = [] ) : WP_Error | array Wrapper for wp_remote_request

Protected Methods

Method Description
_add_query_log ( array $query ) : void Query logging. Don't log anything to the queries property when WP_DEBUG is not enabled. Calls action 'ep_add_query_log' if you want to access the query outside of the ElasticPress plugin. This runs regardless of debufg settings.
parse_order ( string $order ) : string Parse an 'order' query variable and cast it to ASC or DESC as necessary.
parse_orderby ( string $orderbys, $default_order, array $args ) : array Convert the alias to a properly-prefixed sort value.
sanitize_taxonomy_names ( $taxonomies ) : array WP is using 'weird' taxonomy name, for example: 'category' but in query using 'category_name', 'post_tag' but in queries using 'tag' Map taxonomy name in db to taxonomy in query

Private Methods

Method Description
get_parent_terms ( $terms, $term, $tax_name ) : array Recursively get all the ancestor terms of the given term
prepare_date_terms ( $post_date_gmt ) : array Prepare date terms to send to ES.
prepare_terms ( object $post ) : array Prepare terms to send to ES.

Method Details

__construct() public method

Placeholder method
Since: 0.1.0
public __construct ( )

_add_query_log() protected method

Query logging. Don't log anything to the queries property when WP_DEBUG is not enabled. Calls action 'ep_add_query_log' if you want to access the query outside of the ElasticPress plugin. This runs regardless of debufg settings.
protected _add_query_log ( array $query ) : void
$query array Query.
return void Method does not return.

bulk_index_posts() public method

Decode the bulk index response
Since: 0.9.2
public bulk_index_posts ( $body ) : array | object | WP_Error
$body
return array | object | WP_Error

create_network_alias() public method

Create the network alias from an array of indexes
Since: 0.9.0
public create_network_alias ( array $indexes ) : array | boolean
$indexes array
return array | boolean

delete_index() public method

Delete the current index or delete the index passed by name
Since: 0.9.0
public delete_index ( string $index_name = null ) : array | boolean
$index_name string
return array | boolean

delete_network_alias() public method

Delete the network index alias
Since: 0.9.0
public delete_network_alias ( ) : boolean | array
return boolean | array

delete_post() public method

Delete a post from the ES server given a site ID and a host site ID which is used to determine the index to delete from.
Since: 0.1.0
public delete_post ( integer $post_id, boolean $blocking = true ) : boolean
$post_id integer
$blocking boolean
return boolean

elasticpress_enabled() public method

Check to see if we should allow elasticpress to override this query
Since: 0.9.2
public elasticpress_enabled ( $query ) : boolean
$query
return boolean

elasticsearch_can_connect() public method

This function checks if we can connect to Elasticsearch
Since: 2.1

factory() public static method

Return singleton instance of class
Since: 0.1.0
public static factory ( ) : EP_API
return EP_API

format_args() public method

Format WP query args for ES
Since: 0.9.0
public format_args ( array $args ) : array
$args array
return array

format_request_headers() public method

Add appropriate request headers
Since: 1.4
public format_request_headers ( ) : array
return array

get_cluster_status() public method

Retrieves cluster stats from Elasticsearch.
Since: 1.9
public get_cluster_status ( ) : array
return array Contains the status message or the returned statistics.

get_elasticsearch_version() public method

Get Elasticsearch version
Since: 2.1.2

get_index_status() public method

Retrieves index stats from Elasticsearch.
Since: 1.9
public get_index_status ( integer $blog_id = null ) : array
$blog_id integer Id of blog to get stats.
return array Contains the status message or the returned statistics.

get_plugins() public method

Gets a list of available Elasticearch plugins.
Since: 1.9
public get_plugins ( ) : array
return array Array of plugins and their version or error message

get_post() public method

Get a post from the index
Since: 0.9.0
public get_post ( integer $post_id ) : boolean
$post_id integer
return boolean

get_query_log() public method

Return queries for debugging
Since: 1.8
public get_query_log ( ) : array
return array

get_search_status() public method

Retrieves various search statistics from the ES server.
Since: 1.9
public get_search_status ( integer $blog_id = null ) : array
$blog_id integer Id of blog to get stats.
return array Contains the status message or the returned statistics.

get_sites() public method

Wrapper function for get_sites - allows us to have one central place for the ep_indexable_sites filter
public get_sites ( integer $limit ) : mixed | void
$limit integer The maximum amount of sites retrieved, Use 0 to return all sites
return mixed | void

index_exists() public method

Checks if index exists by index name, returns true or false
public index_exists ( null $index_name = null ) : boolean
$index_name null
return boolean

index_post() public method

Index a post under a given site index or the global index ($site_id = 0)
Since: 0.1.0
public index_post ( array $post, boolean $blocking = true ) : array | boolean | mixed
$post array
$blocking boolean
return array | boolean | mixed

is_empty_query() public method

Check if a response array contains results or not
Since: 0.1.2
public is_empty_query ( array $response ) : boolean
$response array
return boolean

parse_api_response() public method

Determines if there is an issue or if the response is valid.
Since: 1.9
public parse_api_response ( object $response ) : array
$response object JSON decoded response from Elasticsearch.
return array Contains the status message or the returned statistics.

parse_order() protected method

Parse an 'order' query variable and cast it to ASC or DESC as necessary.
Since: 1.1
protected parse_order ( string $order ) : string
$order string The 'order' query variable.
return string The sanitized 'order' query variable.

parse_orderby() protected method

Convert the alias to a properly-prefixed sort value.
Since: 1.1
protected parse_orderby ( string $orderbys, $default_order, array $args ) : array
$orderbys string Alias or path for the field to order by.
$args array
return array

parse_site_id() public method

Pull the site id from the index name
Since: 0.9.0
public parse_site_id ( string $index_name ) : integer
$index_name string
return integer

prepare_meta() public method

Prepare post meta to send to ES
Since: 0.1.0
public prepare_meta ( object $post ) : array
$post object
return array

prepare_meta_types() public method

Prepare post meta type values to send to ES
public prepare_meta_types ( array $post_meta ) : array
$post_meta array
return array

prepare_meta_value_types() public method

Prepare meta types for meta value
public prepare_meta_value_types ( mixed $meta_value ) : array
$meta_value mixed
return array

prepare_post() public method

Prepare a post for syncing
Since: 0.9.1
public prepare_post ( integer $post_id ) : boolean | array
$post_id integer
return boolean | array

put_mapping() public method

Send mapping to ES
Since: 0.9.0
public put_mapping ( ) : array | boolean | mixed
return array | boolean | mixed

query() public method

Search for posts under a specific site index or the global index ($site_id = 0).
Since: 0.1.0
public query ( array $args, array $query_args, string $scope = 'current' ) : array
$args array
$query_args array Strictly for debugging
$scope string
return array

refresh_index() public method

Refresh the current index
Since: 0.9.0
public refresh_index ( ) : boolean
return boolean

remote_request() public method

This is a wrapper function for wp_remote_request to account for request failures.
Since: 1.6
public remote_request ( string $path, array $args = [], array $query_args = [] ) : WP_Error | array
$path string Site URL to retrieve.
$args array Optional. Request arguments. Default empty array.
$query_args array Optional. The query args originally passed to WP_Query
return WP_Error | array The response or WP_Error on failure.

sanitize_taxonomy_names() protected method

WP is using 'weird' taxonomy name, for example: 'category' but in query using 'category_name', 'post_tag' but in queries using 'tag' Map taxonomy name in db to taxonomy in query
protected sanitize_taxonomy_names ( $taxonomies ) : array
$taxonomies
return array