Skip to content

Commit 728ccc2

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 92b2c1b commit 728ccc2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

includes/class-solrpower-sync.php

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

0 commit comments

Comments
 (0)