Skip to content

Commit

Permalink
If using the new way to index meta, avoid querying distinct meta fiel…
Browse files Browse the repository at this point in the history
…ds in the sync page
  • Loading branch information
felipeelia committed Dec 10, 2024
1 parent 9b9ad02 commit c549863
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
10 changes: 8 additions & 2 deletions includes/classes/AdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,14 @@ public static function factory() {
protected function check_field_count() {
$post_indexable = Indexables::factory()->get( 'post' );

$indexable_fields = $post_indexable->get_predicted_indexable_meta_keys();
$count_fields_db = count( $indexable_fields );
$search = Features::factory()->get_registered_feature( 'search' );
if ( $search && ! empty( $search->weighting ) && 'manual' === $search->weighting->get_meta_mode() ) {
$indexable_fields = $post_indexable->get_all_allowed_metas_manual();
$count_fields_db = count( $indexable_fields );
} else {
$indexable_fields = $post_indexable->get_predicted_indexable_meta_keys();
$count_fields_db = count( $indexable_fields );
}

$index_name = $post_indexable->get_index_name();
$es_field_limit = Elasticsearch::factory()->get_index_total_fields_limit( $index_name );
Expand Down
27 changes: 27 additions & 0 deletions tests/php/indexables/TestPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -9215,4 +9215,31 @@ public function test_aggregations_return() {
$this->assertArrayHasKey( 'ep_aggregations', $query->query_vars );
$this->assertArrayHasKey( 'my_aggs', $query->query_vars['ep_aggregations'] );
}

/**
* Test the get_all_allowed_metas_manual method
*
* @since 5.1.4
* @group post
*/
public function test_get_all_allowed_metas_manual() {
// Remove product meta data to avoid some noise.
ElasticPress\Features::factory()->get_registered_feature( 'woocommerce' )->tear_down();

// Add some meta data using the Weighting Dashboard
$set_changed_weighting = function( $weighting_default ) {
$weighting_default['post']['meta.allowed_weighting_dashboard.value'] = [
'enabled' => true,
'weight' => 1,
];
return $weighting_default;
};
add_filter( 'ep_weighting_configuration', $set_changed_weighting );

$allowed_metas_manual = ElasticPress\Indexables::factory()->get( 'post' )->get_all_allowed_metas_manual();

$this->assertContains( 'allowed_weighting_dashboard', $allowed_metas_manual );
// Added using the `ep_prepare_meta_allowed_keys` in the test set_up method.
$this->assertContains( 'test_key6', $allowed_metas_manual );
}
}

0 comments on commit c549863

Please sign in to comment.