diff --git a/includes/class-solrpower-wp-query.php b/includes/class-solrpower-wp-query.php index 4408dfbc..bfad4522 100644 --- a/includes/class-solrpower-wp-query.php +++ b/includes/class-solrpower-wp-query.php @@ -59,6 +59,13 @@ class SolrPower_WP_Query { */ public $query; + /** + * Highlighted field snippets + * + * @var array + */ + public $highlighting; + /** * Grab instance of object. * @@ -199,7 +206,10 @@ function posts_request( $request, $query ) { if ( $search->getFacetSet() ) { $this->facets = $search->getFacetSet()->getFacets(); } - $search = $search->getData(); + + $this->highlighting = $search->getHighlighting(); + + $search = $search->getData(); $search_header = $search['responseHeader']; $search = $search['response']; @@ -258,6 +268,23 @@ private function parse_results( $search ) { continue; } + if ( 'solr_id' === $key ) { + if ( $this->highlighting ) { + $highlighted_doc = $this->highlighting->getResult($value); + + if ( $highlighted_doc ) { + $snippet = ''; + + foreach ( $highlighted_doc as $field => $highlight ) { + $snippet .= implode(' ... ', $highlight); + } + + $post->excerpt = $snippet; + continue; + } + } + } + $post->$key = $value; } $post->solr = true;