Skip to content

Commit

Permalink
Updated schema definition and fixed typo
Browse files Browse the repository at this point in the history
  • Loading branch information
Viburnum committed Apr 12, 2017
1 parent cb2d158 commit fd2fdc9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
35 changes: 34 additions & 1 deletion Model/KnpResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use StingerSoft\EntitySearchBundle\Model\ResultSetAdapter;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use StingerSoft\EntitySearchBundle\Model\Document;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;

class KnpResultSet extends ResultSetAdapter implements PaginatableResultSet, ContainerAwareInterface {

Expand All @@ -39,6 +41,11 @@ class KnpResultSet extends ResultSetAdapter implements PaginatableResultSet, Con
* @var \Solarium\Client
*/
protected $client = null;

/**
* @var SlidingPagination|Document[]
*/
protected $lastResult = null;

/**
*
Expand All @@ -60,10 +67,12 @@ public function __construct($client, $query, $term) {
*/
public function paginate($page = 1, $limit = 10, array $options = array()) {
$paginator = $this->container->get('knp_paginator');
return $paginator->paginate(array(
$this->lastResult = $paginator->paginate(array(
$this->client,
$this->query
), $page, $limit, $options);

return $this->lastResult;
}

/**
Expand Down Expand Up @@ -92,4 +101,28 @@ public function getResults($offset = 0, $limit = null) {

return $documents;
}

/**
*
* {@inheritDoc}
*
* @see \StingerSoft\EntitySearchBundle\Model\ResultSet::getExcerpt()
*/
public function getExcerpt(Document $document) {

/**
* @var \Solarium\QueryType\Select\Result\Result $solrResult
*/
$solrResult = $this->lastResult->getCustomParameter('result');

/**
* @var \Solarium\QueryType\Select\Result\Highlighting\Highlighting $highlighting
*/
$highlighting = $solrResult->getHighlighting();
$docHighlight = $highlighting->getResult($document->getFieldValue('id'));

if(!$docHighlight) return null;

return $docHighlight->getField('content');
}
}
Binary file modified Resources/solr/conf.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion Services/SearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function saveDocument(\StingerSoft\EntitySearchBundle\Model\Document $doc



if($query->getFile()) {
if($document->getFile()) {
$query->setDocument($doc);
$query->setCommit(true);
$client->extract($query);
Expand Down

0 comments on commit fd2fdc9

Please sign in to comment.