Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 53 additions & 50 deletions inc/classes/algolia/class-algolia-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,55 +158,58 @@
continue;
}

$base_record = [
'objectID' => $site_key . '_' . $post->ID,
'title' => $post->post_title,
'excerpt' => get_the_excerpt( $post ),
'content' => $post->post_content,
'clean_content' => $this->get_clean_content( $post->post_content ),
'name' => $post->post_name,
'type' => $post->post_type,
'permalink' => get_permalink( $post->ID ),
'taxonomies' => $this->get_all_taxonomies( $post ),
'date' => $post->post_date,
'modified' => $post->post_modified,
'thumbnail' => get_the_post_thumbnail_url( $post->ID ),
'site_url' => $site_url,
'site_name' => $site_name,
'site_key' => $site_key,
'post_id' => $post->ID,
'postDate' => $post->post_date,
'postDateGmt' => $post->post_date_gmt,
'author_ID' => $post->post_author,
'author_login' => get_the_author_meta( 'user_login', $post->post_author ),
'author_nicename' => get_the_author_meta( 'user_nicename', $post->post_author ),
'author_email' => get_the_author_meta( 'user_email', $post->post_author ),
'author_registered' => get_the_author_meta( 'user_registered', $post->post_author ),
'author_display_name' => get_the_author_meta( 'display_name', $post->post_author ),
'author_first_name' => get_the_author_meta( 'first_name', $post->post_author ),
'author_last_name' => get_the_author_meta( 'last_name', $post->post_author ),
'author_description' => get_the_author_meta( 'description', $post->post_author ),
'author_avatar' => get_avatar_url( $post->post_author ),
'author_posts_url' => get_author_posts_url( $post->post_author ),
'parent_post_id' => $site_key . '_' . $post->ID, // Used for Algolia distinct/grouping.
'is_chunked' => false,
'onesearch_chunk_index' => 0,
'onesearch_total_chunks' => 1,
];

/**
* Allow modification of the record payload.
*
* @param array $base_record Record being indexed.
* @param \WP_Post $post Source post.
*/
$filtered_record = apply_filters( 'onesearch_algolia_index_data', $base_record, $post );

// Segment records that exceed the size threshold.
$chunks = $this->maybe_chunk_record( $filtered_record );

// Add chunks to records array.
$records = array_merge( $records, $chunks );
try {
$base_record = [
'objectID' => $site_key . '_' . $post->ID,
'title' => $post->post_title,
'excerpt' => get_the_excerpt( $post ),
'content' => $post->post_content,
'clean_content' => $this->get_clean_content( $post->post_content ),
'name' => $post->post_name,
'type' => $post->post_type,
'permalink' => get_permalink( $post->ID ),
'taxonomies' => $this->get_all_taxonomies( $post ),
'date' => $post->post_date,
'modified' => $post->post_modified,
'thumbnail' => get_the_post_thumbnail_url( $post->ID ),
'site_url' => $site_url,
'site_name' => $site_name,
'site_key' => $site_key,
'post_id' => $post->ID,
'postDate' => $post->post_date,
'postDateGmt' => $post->post_date_gmt,
'author_ID' => $post->post_author,
'author_login' => get_the_author_meta( 'user_login', $post->post_author ),

Check failure on line 182 in inc/classes/algolia/class-algolia-index.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Parameter #2 $user_id of function get_the_author_meta expects int|false, string given.
'author_nicename' => get_the_author_meta( 'user_nicename', $post->post_author ),

Check failure on line 183 in inc/classes/algolia/class-algolia-index.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Parameter #2 $user_id of function get_the_author_meta expects int|false, string given.
'author_email' => get_the_author_meta( 'user_email', $post->post_author ),

Check failure on line 184 in inc/classes/algolia/class-algolia-index.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Parameter #2 $user_id of function get_the_author_meta expects int|false, string given.
'author_registered' => get_the_author_meta( 'user_registered', $post->post_author ),

Check failure on line 185 in inc/classes/algolia/class-algolia-index.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Parameter #2 $user_id of function get_the_author_meta expects int|false, string given.
'author_display_name' => get_the_author_meta( 'display_name', $post->post_author ),

Check failure on line 186 in inc/classes/algolia/class-algolia-index.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Parameter #2 $user_id of function get_the_author_meta expects int|false, string given.
'author_first_name' => get_the_author_meta( 'first_name', $post->post_author ),

Check failure on line 187 in inc/classes/algolia/class-algolia-index.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Parameter #2 $user_id of function get_the_author_meta expects int|false, string given.
'author_last_name' => get_the_author_meta( 'last_name', $post->post_author ),

Check failure on line 188 in inc/classes/algolia/class-algolia-index.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Parameter #2 $user_id of function get_the_author_meta expects int|false, string given.
'author_description' => get_the_author_meta( 'description', $post->post_author ),

Check failure on line 189 in inc/classes/algolia/class-algolia-index.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Parameter #2 $user_id of function get_the_author_meta expects int|false, string given.
'author_avatar' => get_avatar_url( $post->post_author ),
'author_posts_url' => get_author_posts_url( $post->post_author ),

Check failure on line 191 in inc/classes/algolia/class-algolia-index.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Parameter #1 $author_id of function get_author_posts_url expects int, string given.
'parent_post_id' => $site_key . '_' . $post->ID, // Used for Algolia distinct/grouping.
'is_chunked' => false,
'onesearch_chunk_index' => 0,
'onesearch_total_chunks' => 1,
];

/**
* Allow modification of the record payload.
*
* @param array<string,mixed> $base_record Record being indexed.
* @param \WP_Post $post Source post.
*/
$filtered_record = apply_filters( 'onesearch_algolia_index_data', $base_record, $post );

// Segment records that exceed the size threshold.
$chunks = $this->maybe_chunk_record( $filtered_record );

// Add chunks to records array.
$records = array_merge( $records, $chunks );
} catch ( \Throwable $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch -- @todo errors should be logged.
Comment thread
justlevine marked this conversation as resolved.
}

// Free memory after processing each post.
unset( $base_record, $filtered_record, $chunks );
Comment thread
justlevine marked this conversation as resolved.
Expand Down Expand Up @@ -255,7 +258,7 @@

// Remove excessive blank lines and normalize whitespace.
$clean_content = preg_replace( '/\s*\n\s*/', "\n", $clean_content ); // collapse blank lines.
$clean_content = preg_replace( '/\n{2,}/', "\n", $clean_content ); // limit to single newlines.

Check failure on line 261 in inc/classes/algolia/class-algolia-index.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Parameter #3 $subject of function preg_replace expects array<float|int|string>|string, string|null given.
$clean_content = trim( (string) $clean_content );

return $clean_content;
Expand Down Expand Up @@ -329,7 +332,7 @@
*
* Handles UTF-8 sanitization and returns records ready for Algolia indexing.
*
* @param array $record Record to evaluate and possibly split.
* @param array<string,mixed> $record Record to evaluate and possibly split.
*
* @return array<array<string,mixed>> Array of one or more records.
*/
Expand Down
Loading