PHP Класс EP_API

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__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

Защищенные методы

Метод Описание
_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

Приватные методы

Метод Описание
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.

Описание методов

__construct() публичный Метод

Placeholder method
С версии: 0.1.0
public __construct ( )

_add_query_log() защищенный Метод

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.
Результат void Method does not return.

bulk_index_posts() публичный Метод

Decode the bulk index response
С версии: 0.9.2
public bulk_index_posts ( $body ) : array | object | WP_Error
$body
Результат array | object | WP_Error

create_network_alias() публичный Метод

Create the network alias from an array of indexes
С версии: 0.9.0
public create_network_alias ( array $indexes ) : array | boolean
$indexes array
Результат array | boolean

delete_index() публичный Метод

Delete the current index or delete the index passed by name
С версии: 0.9.0
public delete_index ( string $index_name = null ) : array | boolean
$index_name string
Результат array | boolean

delete_network_alias() публичный Метод

Delete the network index alias
С версии: 0.9.0
public delete_network_alias ( ) : boolean | array
Результат boolean | array

delete_post() публичный Метод

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.
С версии: 0.1.0
public delete_post ( integer $post_id, boolean $blocking = true ) : boolean
$post_id integer
$blocking boolean
Результат boolean

elasticpress_enabled() публичный Метод

Check to see if we should allow elasticpress to override this query
С версии: 0.9.2
public elasticpress_enabled ( $query ) : boolean
$query
Результат boolean

elasticsearch_can_connect() публичный Метод

This function checks if we can connect to Elasticsearch
С версии: 2.1
public elasticsearch_can_connect ( ) : boolean
Результат boolean

factory() публичный статический Метод

Return singleton instance of class
С версии: 0.1.0
public static factory ( ) : EP_API
Результат EP_API

format_args() публичный Метод

Format WP query args for ES
С версии: 0.9.0
public format_args ( array $args ) : array
$args array
Результат array

format_request_headers() публичный Метод

Add appropriate request headers
С версии: 1.4
public format_request_headers ( ) : array
Результат array

get_cluster_status() публичный Метод

Retrieves cluster stats from Elasticsearch.
С версии: 1.9
public get_cluster_status ( ) : array
Результат array Contains the status message or the returned statistics.

get_elasticsearch_version() публичный Метод

Get Elasticsearch version
С версии: 2.1.2
public get_elasticsearch_version ( ) : string
Результат string

get_index_status() публичный Метод

Retrieves index stats from Elasticsearch.
С версии: 1.9
public get_index_status ( integer $blog_id = null ) : array
$blog_id integer Id of blog to get stats.
Результат array Contains the status message or the returned statistics.

get_plugins() публичный Метод

Gets a list of available Elasticearch plugins.
С версии: 1.9
public get_plugins ( ) : array
Результат array Array of plugins and their version or error message

get_post() публичный Метод

Get a post from the index
С версии: 0.9.0
public get_post ( integer $post_id ) : boolean
$post_id integer
Результат boolean

get_query_log() публичный Метод

Return queries for debugging
С версии: 1.8
public get_query_log ( ) : array
Результат array

get_search_status() публичный Метод

Retrieves various search statistics from the ES server.
С версии: 1.9
public get_search_status ( integer $blog_id = null ) : array
$blog_id integer Id of blog to get stats.
Результат array Contains the status message or the returned statistics.

get_sites() публичный Метод

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
Результат mixed | void

index_exists() публичный Метод

Checks if index exists by index name, returns true or false
public index_exists ( null $index_name = null ) : boolean
$index_name null
Результат boolean

index_post() публичный Метод

Index a post under a given site index or the global index ($site_id = 0)
С версии: 0.1.0
public index_post ( array $post, boolean $blocking = true ) : array | boolean | mixed
$post array
$blocking boolean
Результат array | boolean | mixed

is_empty_query() публичный Метод

Check if a response array contains results or not
С версии: 0.1.2
public is_empty_query ( array $response ) : boolean
$response array
Результат boolean

parse_api_response() публичный Метод

Determines if there is an issue or if the response is valid.
С версии: 1.9
public parse_api_response ( object $response ) : array
$response object JSON decoded response from Elasticsearch.
Результат array Contains the status message or the returned statistics.

parse_order() защищенный Метод

Parse an 'order' query variable and cast it to ASC or DESC as necessary.
С версии: 1.1
protected parse_order ( string $order ) : string
$order string The 'order' query variable.
Результат string The sanitized 'order' query variable.

parse_orderby() защищенный Метод

Convert the alias to a properly-prefixed sort value.
С версии: 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
Результат array

parse_site_id() публичный Метод

Pull the site id from the index name
С версии: 0.9.0
public parse_site_id ( string $index_name ) : integer
$index_name string
Результат integer

prepare_meta() публичный Метод

Prepare post meta to send to ES
С версии: 0.1.0
public prepare_meta ( object $post ) : array
$post object
Результат array

prepare_meta_types() публичный Метод

Prepare post meta type values to send to ES
public prepare_meta_types ( array $post_meta ) : array
$post_meta array
Результат array

prepare_meta_value_types() публичный Метод

Prepare meta types for meta value
public prepare_meta_value_types ( mixed $meta_value ) : array
$meta_value mixed
Результат array

prepare_post() публичный Метод

Prepare a post for syncing
С версии: 0.9.1
public prepare_post ( integer $post_id ) : boolean | array
$post_id integer
Результат boolean | array

put_mapping() публичный Метод

Send mapping to ES
С версии: 0.9.0
public put_mapping ( ) : array | boolean | mixed
Результат array | boolean | mixed

query() публичный Метод

Search for posts under a specific site index or the global index ($site_id = 0).
С версии: 0.1.0
public query ( array $args, array $query_args, string $scope = 'current' ) : array
$args array
$query_args array Strictly for debugging
$scope string
Результат array

refresh_index() публичный Метод

Refresh the current index
С версии: 0.9.0
public refresh_index ( ) : boolean
Результат boolean

remote_request() публичный Метод

This is a wrapper function for wp_remote_request to account for request failures.
С версии: 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
Результат WP_Error | array The response or WP_Error on failure.

sanitize_taxonomy_names() защищенный Метод

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
Результат array