Skip to content

Commit

Permalink
feat: score sort clause
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian ALEXANDRE committed Dec 11, 2018
1 parent 9cedae2 commit d636241
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/bundle/Resources/config/services.yml
Expand Up @@ -54,9 +54,27 @@ services:
tags:
- {name: ezpublish.search.solr.query.content.criterion_visitor}

Novactive\EzSolrSearchExtra\Query\Content\CriterionVisitor\MultipleFieldsFullText:
tags:
- {name: ezpublish.search.solr.query.content.criterion_visitor}

Novactive\EzSolrSearchExtra\Query\CriterionHandler\MultipleFieldsFullText:
arguments:
$dbHandler: "@ezpublish.api.storage_engine.legacy.dbhandler"
tags:
- {name: ezpublish.search.legacy.gateway.criterion_handler.content}
- {name: ezpublish.search.legacy.gateway.criterion_handler.location}

Novactive\EzSolrSearchExtra\Query\SortClauseVisitor\Score:
tags:
- {name: ezpublish.search.solr.query.content.sort_clause_visitor}
- {name: ezpublish.search.solr.query.location.sort_clause_visitor}

Novactive\EzSolrSearchExtra\Query\SortClauseHandler\Score:
autowire: false
autoconfigure: false
public: false
parent: ezpublish.search.legacy.gateway.sort_clause_handler.base
tags:
- {name: ezpublish.search.legacy.gateway.sort_clause_handler.content}
- {name: ezpublish.search.legacy.gateway.sort_clause_handler.location}
30 changes: 30 additions & 0 deletions src/lib/Query/SortClause/Score.php
@@ -0,0 +1,30 @@
<?php
/**
* NovaeZSolrSearchExtraBundle.
*
* @package NovaeZSolrSearchExtraBundle
*
* @author Novactive <f.alexandre@novactive.com>
* @copyright 2018 Novactive
* @license https://github.com/Novactive/NovaeZSolrSearchExtraBundle/blob/master/LICENSE
*/

namespace Novactive\EzSolrSearchExtra\Query\SortClause;

use eZ\Publish\API\Repository\Values\Content\Query\SortClause;

/**
* Class Score.
*/
class Score extends SortClause
{
/**
* Constructs a new Score SortClause.
*
* @param string $sortDirection
*/
public function __construct($sortDirection = Query::SORT_ASC)
{
parent::__construct('score', $sortDirection);
}
}
39 changes: 39 additions & 0 deletions src/lib/Query/SortClauseHandler/Score.php
@@ -0,0 +1,39 @@
<?php
/**
* NovaeZSolrSearchExtraBundle.
*
* @package NovaeZSolrSearchExtraBundle
*
* @author Novactive <f.alexandre@novactive.com>
* @copyright 2018 Novactive
* @license https://github.com/Novactive/NovaeZSolrSearchExtraBundle/blob/master/LICENSE
*/

namespace Novactive\EzSolrSearchExtra\Query\SortClauseHandler;

use eZ\Publish\API\Repository\Values\Content\Query\SortClause as APISortClause;
use eZ\Publish\Core\Persistence\Database\SelectQuery;
use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler;
use Novactive\EzSolrSearchExtra\Query\SortClause;

/**
* Class Score.
*/
class Score extends SortClauseHandler
{
/**
* {@inheritdoc}
*/
public function accept(APISortClause $sortClause)
{
return $sortClause instanceof SortClause\Score;
}

/**
* {@inheritdoc}
*/
public function applySelect(SelectQuery $query, APISortClause $sortClause, $number)
{
return null;
}
}
46 changes: 46 additions & 0 deletions src/lib/Query/SortClauseVisitor/Score.php
@@ -0,0 +1,46 @@
<?php
/**
* NovaeZSolrSearchExtraBundle.
*
* @package NovaeZSolrSearchExtraBundle
*
* @author Novactive <f.alexandre@novactive.com>
* @copyright 2018 Novactive
* @license https://github.com/Novactive/NovaeZSolrSearchExtraBundle/blob/master/LICENSE
*/

namespace Novactive\EzSolrSearchExtra\Query\SortClauseVisitor;

use eZ\Publish\API\Repository\Values\Content\Query\SortClause as APISortClause;
use EzSystems\EzPlatformSolrSearchEngine\Query\SortClauseVisitor;
use Novactive\EzSolrSearchExtra\Query\SortClause;

/**
* Class Score.
*/
class Score extends SortClauseVisitor
{
/**
* Check if visitor is applicable to current sortClause.
*
* @param APISortClause $sortClause
*
* @return bool
*/
public function canVisit(APISortClause $sortClause)
{
return $sortClause instanceof SortClause\Score;
}

/**
* Map field value to a proper Solr representation.
*
* @param APISortClause $sortClause
*
* @return string
*/
public function visit(APISortClause $sortClause)
{
return 'score' . $this->getDirection($sortClause);
}
}

0 comments on commit d636241

Please sign in to comment.