Skip to content

Commit

Permalink
Support for indexing serialized arrays
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mweimerskirch committed Dec 5, 2018
1 parent d3bb9c9 commit 671e1a3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion includes/class-solrpower-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,15 @@ function build_document(
$doc->addField( $field_name . '_d', floatval( preg_replace( '/[^-0-9\.]/', '', $value ) ) );
$doc->addField( $field_name . '_f', floatval( preg_replace( '/[^-0-9\.]/', '', $value ) ) );
}
$doc->addField( $field_name . '_s', $value );
if( is_serialized( $value ) ) {
// If the value is an array, recursively "implode" all values with a linebreak character
$imploded_string = '';
array_walk_recursive( unserialize($value), function ( $val, $key ) use ( &$imploded_string ) {
$imploded_string .= $val . "\n";
} );
$value = $imploded_string;
}
$doc->addField( $field_name . '_s', $value );
}
$doc->addField( $field_name . '_srch', $value );
$used[] = $field_name;
Expand Down

0 comments on commit 671e1a3

Please sign in to comment.