Skip to content

Commit

Permalink
Merge pull request #9 from blacksesion/master
Browse files Browse the repository at this point in the history
add highlight to model
  • Loading branch information
Sammaye authored Nov 11, 2016
2 parents 9379c13 + 59fa7f4 commit 225380d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion SolrDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use yii\di\Instance;
use Solarium\Core\Query\QueryInterface as SolrQuery;
use sammaye\solr\Client;
use yii\helpers\Html;

/**
* This is the SolrDataProvider
Expand Down Expand Up @@ -91,10 +92,20 @@ public function prepareModels()
}
}
$resultset = $this->solr->select($this->query);
$highlighting = $resultset->getHighlighting();
$models = [];
foreach($resultset as $result){
$cname = $this->modelClass;
$models[] = $cname::populateFromSolr($result);
$model = $cname::populateFromSolr($result);
if (isset($highlighting) && $highlighting != null) {
$highlightedDoc = $highlighting->getResult($result->id);
if ($highlightedDoc) {
foreach ($highlightedDoc as $field => $highlight) {
$model->highlight .= Html::decode(implode(' (...) ', $highlight) . '<br/>');
}
}
}
$models[] = $model;
}
return $models;
}
Expand Down

0 comments on commit 225380d

Please sign in to comment.