From 671e1a34ff41f2169ab9a479a77ec79d48e414e9 Mon Sep 17 00:00:00 2001 From: Michel Weimerskirch Date: Wed, 29 Nov 2017 14:54:01 +0100 Subject: [PATCH] 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. --- includes/class-solrpower-sync.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/includes/class-solrpower-sync.php b/includes/class-solrpower-sync.php index 81b77be4..58d111fd 100644 --- a/includes/class-solrpower-sync.php +++ b/includes/class-solrpower-sync.php @@ -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;