Indexer implements Registerable
Handles indexing of posts.
Interfaces, Classes and Traits
- Registerable
Table of Contents
- $chunk_size : int
- Number of posts to index before updating progress.
- $facet : Filter
- The individual facet (filter) being processed.
- $is_saving : bool
- Is wp_insert_post running?
- create_attribute_filter() : void
- When a new attribute has been added check if an "all" attribute exists, if it does - create the child filter.
- delete_attribute_filter() : void
- Delete the related attribute filter when an attribute is removed.
- delete_post() : void
- Delete indexed data when a post is deleted.
- delete_term() : void
- Cleanup term related data from the index, when the term is deleted.
- edit_term() : void
- Update indexed data when a product related term (taxonomy & attribute) is saved.
- get_chunk_size() : int|string
- Get the chunk size for batch indexing.
- get_post_ids_to_index() : array<string|int, mixed>
- Get an array of post IDs to index.
- index() : void
- Rebuild the index for all or a given post.
- index_batch() : void
- Run the indexing process of all products in batches.
- index_on_csv_import() : void
- Index products when they're added via csv import.
- index_post() : void
- Index an individual post.
- index_row() : void
- Pre-process the indexed data before insertion.
- insert() : string
- Insert the indexed data into the database table.
- is_batch_index_running() : bool
- Determine if batch indexing is currently running.
- is_silently_running() : bool
- Determine if the indexing is silently running.
- is_wp_insert_post() : mixed
- We're hijacking wp_insert_post_parent Prevent our set_object_terms() hook from firing within wp_insert_post
- register() : void
- Hook into WP to keeps the index up to date.
- safe_value() : string
- Hash a facet value if needed
- save_post() : void
- Update the index when a post is saved.
- set_index_running() : void
- Set a flag in the database to mark the index as running
- set_object_terms() : void
- Support for manual taxonomy associations.
- should_skip_hidden_products() : bool
- Determine if hidden products should be skipped during indexing.
- update_attribute_filters() : void
- When an attribute has been updated, find any attribute filters and update it's details.
- get_row_data() : array<string|int, mixed>
- Find the data for the specified facet.
Properties
$chunk_size
Number of posts to index before updating progress.
public
int
$chunk_size
= 30
$facet
The individual facet (filter) being processed.
public
Filter
$facet
$is_saving
Is wp_insert_post running?
public
bool
$is_saving
= false
Methods
create_attribute_filter()
When a new attribute has been added check if an "all" attribute exists, if it does - create the child filter.
public
create_attribute_filter(int $id, array<string|int, mixed> $data) : void
Parameters
- $id : int
-
Added attribute ID.
- $data : array<string|int, mixed>
-
Attribute data.
Return values
void —delete_attribute_filter()
Delete the related attribute filter when an attribute is removed.
public
delete_attribute_filter(int $id, string $name, string $taxonomy) : void
Parameters
- $id : int
-
Attribute ID.
- $name : string
-
Attribute name.
- $taxonomy : string
-
Attribute taxonomy name.
Return values
void —delete_post()
Delete indexed data when a post is deleted.
public
delete_post(string $post_id) : void
Parameters
- $post_id : string
Return values
void —delete_term()
Cleanup term related data from the index, when the term is deleted.
public
delete_term(string $term_id, string $tt_id, string $taxonomy) : void
Parameters
- $term_id : string
- $tt_id : string
- $taxonomy : string
Return values
void —edit_term()
Update indexed data when a product related term (taxonomy & attribute) is saved.
public
edit_term(string $term_id, string $tt_id, string $taxonomy) : void
Parameters
- $term_id : string
- $tt_id : string
- $taxonomy : string
Return values
void —get_chunk_size()
Get the chunk size for batch indexing.
public
get_chunk_size() : int|string
Return values
int|string —get_post_ids_to_index()
Get an array of post IDs to index.
public
get_post_ids_to_index([bool|string|int $post_id = false ][, bool|int|string $offset = false ][, bool|int|string $limit = false ]) : array<string|int, mixed>
Parameters
- $post_id : bool|string|int = false
- $offset : bool|int|string = false
- $limit : bool|int|string = false
Return values
array<string|int, mixed> —index()
Rebuild the index for all or a given post.
public
index([bool|string|int $post_id = false ]) : void
Parameters
- $post_id : bool|string|int = false
-
false to re-index everything.
Return values
void —index_batch()
Run the indexing process of all products in batches.
public
index_batch(int $offset, int $limit) : void
Parameters
- $offset : int
-
WP_Query offset parameter.
- $limit : int
-
WP_Query posts_per_page parameter.
Return values
void —index_on_csv_import()
Index products when they're added via csv import.
public
index_on_csv_import(object $object, array<string|int, mixed> $data) : void
Parameters
- $object : object
-
Product instance.
- $data : array<string|int, mixed>
Return values
void —index_post()
Index an individual post.
public
index_post(string $post_id, Collection $filters) : void
Parameters
- $post_id : string
- $filters : Collection
Return values
void —index_row()
Pre-process the indexed data before insertion.
public
index_row(array<string|int, mixed> $params) : void
Parameters
- $params : array<string|int, mixed>
-
indexed data for the processed facet
Return values
void —insert()
Insert the indexed data into the database table.
public
insert(array<string|int, mixed> $params) : string
Parameters
- $params : array<string|int, mixed>
-
indexed data
Return values
string —ID number of the row belonging to the data
is_batch_index_running()
Determine if batch indexing is currently running.
public
is_batch_index_running() : bool
Return values
bool —is_silently_running()
Determine if the indexing is silently running.
public
is_silently_running() : bool
Return values
bool —is_wp_insert_post()
We're hijacking wp_insert_post_parent Prevent our set_object_terms() hook from firing within wp_insert_post
public
is_wp_insert_post(string $post_parent) : mixed
Parameters
- $post_parent : string
Return values
mixed —register()
Hook into WP to keeps the index up to date.
public
register() : void
Return values
void —safe_value()
Hash a facet value if needed
public
safe_value(string $value) : string
Parameters
- $value : string
Return values
string —save_post()
Update the index when a post is saved.
public
save_post(string $post_id) : void
Parameters
- $post_id : string
Return values
void —set_index_running()
Set a flag in the database to mark the index as running
public
set_index_running(bool $running[, bool $silently = false ]) : void
Parameters
- $running : bool
-
whether or not the index is running.
- $silently : bool = false
-
whether or not the indexer should be running silently (no admin notice displayed)
Return values
void —set_object_terms()
Support for manual taxonomy associations.
public
set_object_terms(string|int $object_id) : void
Parameters
- $object_id : string|int
Return values
void —should_skip_hidden_products()
Determine if hidden products should be skipped during indexing.
public
should_skip_hidden_products() : bool
Return values
bool —update_attribute_filters()
When an attribute has been updated, find any attribute filters and update it's details.
public
update_attribute_filters(int $id, array<string|int, mixed> $data, string $old_slug) : void
Parameters
- $id : int
-
Added attribute ID.
- $data : array<string|int, mixed>
-
Attribute data.
- $old_slug : string
-
Attribute old name.
Return values
void —get_row_data()
Find the data for the specified facet.
private
get_row_data(array<string|int, mixed> $defaults) : array<string|int, mixed>
Parameters
- $defaults : array<string|int, mixed>