PHP Class EP_API

Afficher le fichier Open project: 10up/elasticpress Class Usage Examples

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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

Méthode 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 méthode

Placeholder method
Since: 0.1.0
public __construct ( )

_add_query_log() protected méthode

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.
Résultat void Method does not return.

bulk_index_posts() public méthode

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

create_network_alias() public méthode

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

delete_index() public méthode

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
Résultat array | boolean

delete_network_alias() public méthode

Delete the network index alias
Since: 0.9.0
public delete_network_alias ( ) : boolean | array
Résultat boolean | array

delete_post() public méthode

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
Résultat boolean

elasticpress_enabled() public méthode

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

elasticsearch_can_connect() public méthode

This function checks if we can connect to Elasticsearch
Since: 2.1
public elasticsearch_can_connect ( ) : boolean
Résultat boolean

factory() public static méthode

Return singleton instance of class
Since: 0.1.0
public static factory ( ) : EP_API
Résultat EP_API

format_args() public méthode

Format WP query args for ES
Since: 0.9.0
public format_args ( array $args ) : array
$args array
Résultat array

format_request_headers() public méthode

Add appropriate request headers
Since: 1.4
public format_request_headers ( ) : array
Résultat array

get_cluster_status() public méthode

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

get_elasticsearch_version() public méthode

Get Elasticsearch version
Since: 2.1.2
public get_elasticsearch_version ( ) : string
Résultat string

get_index_status() public méthode

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.
Résultat array Contains the status message or the returned statistics.

get_plugins() public méthode

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

get_post() public méthode

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

get_query_log() public méthode

Return queries for debugging
Since: 1.8
public get_query_log ( ) : array
Résultat array

get_search_status() public méthode

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.
Résultat array Contains the status message or the returned statistics.

get_sites() public méthode

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
Résultat mixed | void

index_exists() public méthode

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

index_post() public méthode

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
Résultat array | boolean | mixed

is_empty_query() public méthode

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

parse_api_response() public méthode

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.
Résultat array Contains the status message or the returned statistics.

parse_order() protected méthode

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.
Résultat string The sanitized 'order' query variable.

parse_orderby() protected méthode

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
Résultat array

parse_site_id() public méthode

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

prepare_meta() public méthode

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

prepare_meta_types() public méthode

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

prepare_meta_value_types() public méthode

Prepare meta types for meta value
public prepare_meta_value_types ( mixed $meta_value ) : array
$meta_value mixed
Résultat array

prepare_post() public méthode

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

put_mapping() public méthode

Send mapping to ES
Since: 0.9.0
public put_mapping ( ) : array | boolean | mixed
Résultat array | boolean | mixed

query() public méthode

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
Résultat array

refresh_index() public méthode

Refresh the current index
Since: 0.9.0
public refresh_index ( ) : boolean
Résultat boolean

remote_request() public méthode

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
Résultat WP_Error | array The response or WP_Error on failure.

sanitize_taxonomy_names() protected méthode

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
Résultat array