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 Nov 29, 2017
1 parent 92b2c1b commit 728ccc2
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 @@ -370,7 +370,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 728ccc2

Please sign in to comment.