Skip to content
Permalink
Browse files

feat: sort clause on solr field

Signed-off-by: Florian ALEXANDRE <f.alexandre@novactive.com>
  • Loading branch information...
florianalexandre committed Feb 21, 2019
1 parent 8ee33dc commit 2ded1bf92f29c65fba2c86812065077a79e84380
@@ -87,6 +87,20 @@ services:
- {name: ezpublish.search.legacy.gateway.sort_clause_handler.content}
- {name: ezpublish.search.legacy.gateway.sort_clause_handler.location}

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

Novactive\EzSolrSearchExtra\Query\SortClauseHandler\CustomField:
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}

Novactive\EzSolrSearchExtra\Query\Common\FacetBuilderVisitor\CustomField:
tags:
- {name: ezpublish.search.solr.query.content.facet_builder_visitor}
@@ -0,0 +1,33 @@
<?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;
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
/**
* Class CustomField.
*/
class CustomField extends SortClause
{
/**
* Constructs a new CustomField SortClause.
*
* @param string $fieldIdentifier
* @param string $sortDirection
*/
public function __construct(string $fieldIdentifier, $sortDirection = Query::SORT_ASC)
{
parent::__construct($fieldIdentifier, $sortDirection);
}
}
@@ -11,6 +11,7 @@
namespace Novactive\EzSolrSearchExtra\Query\SortClause;
use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
/**
@@ -0,0 +1,40 @@
<?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 CustomField.
*/
class CustomField extends SortClauseHandler
{
/**
* {@inheritdoc}
*/
public function accept(APISortClause $sortClause)
{
return $sortClause instanceof SortClause\CustomField;
}
/**
* {@inheritdoc}
*/
public function applySelect(SelectQuery $query, APISortClause $sortClause, $number)
{
return null;
}
}
@@ -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 CustomField.
*/
class CustomField extends SortClauseVisitor
{
/**
* Check if visitor is applicable to current sortClause.
*
* @param APISortClause $sortClause
*
* @return bool
*/
public function canVisit(APISortClause $sortClause)
{
return $sortClause instanceof SortClause\CustomField;
}
/**
* Map field value to a proper Solr representation.
*
* @param APISortClause $sortClause
*
* @return string
*/
public function visit(APISortClause $sortClause)
{
return $sortClause->target . $this->getDirection($sortClause);
}
}

0 comments on commit 2ded1bf

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.