Skip to content

Commit 671e1a3

Browse files
committed
Support for indexing serialized arrays
If the value is an array, recursively "implode" all values with a linebreak character. Many plugins store data (e. g. repeatable text boxes) as serialized arrays in the post_meta table. This changes makes it easier to index them properly without indexing control characters or array index names.
1 parent d3bb9c9 commit 671e1a3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

includes/class-solrpower-sync.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,15 @@ function build_document(
371371
$doc->addField( $field_name . '_d', floatval( preg_replace( '/[^-0-9\.]/', '', $value ) ) );
372372
$doc->addField( $field_name . '_f', floatval( preg_replace( '/[^-0-9\.]/', '', $value ) ) );
373373
}
374-
$doc->addField( $field_name . '_s', $value );
374+
if( is_serialized( $value ) ) {
375+
// If the value is an array, recursively "implode" all values with a linebreak character
376+
$imploded_string = '';
377+
array_walk_recursive( unserialize($value), function ( $val, $key ) use ( &$imploded_string ) {
378+
$imploded_string .= $val . "\n";
379+
} );
380+
$value = $imploded_string;
381+
}
382+
$doc->addField( $field_name . '_s', $value );
375383
}
376384
$doc->addField( $field_name . '_srch', $value );
377385
$used[] = $field_name;

0 commit comments

Comments
 (0)