Splitting large shared attributes

Currently, I’m using the WordPress plugin and a custom function to add custom attributes through the algolia_post_shared_attributes and algolia_searchable_post_shared_attributes filters. Now I need to add an extra attribute (a post meta value), which sometimes exceeds the 10Kb record limit.

As far as I understand, I can’t use the filters mentioned above to split these attributes in a way that results in multiple records in the index.

So how would I go about solving this? Ideal would be if I could change the settings object so the plugin understands which attribute might require splitting, comparable with how the post content field is handled by default.

No reply? That’s not promising. :confused:

Does that imply I need to re-implement the Algolia plugin for WordPress?

This is an attempt to actually solve this issue, making use of the algolia_post_records and algolia_searchable_post_records filters:

<?php

function my_post_updated_split_my_meta_field( array $records, WP_Post $post ) {

	$meta  = get_post_meta( $post->ID, 'my_meta_field', true );
	$parts = Algolia_Utils::explode_content( $meta );

	$new_record  = $records[0];
	$new_records = [];

	// Merge records (content field)
	if ( count( $records ) > 0 ) {
		$content = '';
		foreach ( $records as $record ) {
			$content .= $record['content'];
		}
		$new_record['content'] = $content;
	}

	// Create new records
	foreach ( $parts as $part ) {
		$new_record['meta_field'] = $part;
		$new_records[]     = $new_record;
	}

	return $new_records;
}
add_filter( 'algolia_post_records', 'my_post_updated_split_my_meta_field', 10, 2 );
add_filter( 'algolia_searchable_post_records', 'my_post_updated_split_my_meta_field', 10, 2 );

This seems to work, but I do need to re-merge the content field because: there is no obvious way to split multiple large fields (i.e. both content and my_meta_field).

I’d really appreciate some feedback on the chosen implementation so far.