Skip to content

Commit

Permalink
Implement custom field sort clause
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyCupic authored and pspanja committed Aug 19, 2019
1 parent 2dcc112 commit 622139f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/API/Values/Content/Query/SortClause/CustomField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Netgen\EzPlatformSearchExtra\API\Values\Content\Query\SortClause;

use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
use Netgen\EzPlatformSearchExtra\API\Values\Content\Query\Criterion\SubdocumentQuery;
use Netgen\EzPlatformSearchExtra\API\Values\Content\Query\SortClause\Target\SubdocumentTarget;

/**
* CustomField sort clause is used to sort Content by custom field indexed for this content.
*/
final class CustomField extends SortClause
{
/**
* @param string $fieldName
* @param string $sortDirection
*/
public function __construct($fieldName, $sortDirection = Query::SORT_ASC)
{
parent::__construct($fieldName, $sortDirection);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Netgen\EzPlatformSearchExtra\Core\Search\Solr\Query\Common\SortClauseVisitor;

use EzSystems\EzPlatformSolrSearchEngine\Query\SortClauseVisitor;
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
use \Netgen\EzPlatformSearchExtra\API\Values\Content\Query\SortClause\CustomField as CustomFieldSortClause;

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

/**
* Map field value to a proper Solr representation.
*
* @param SortClause $sortClause
*
* @return string
*/
public function visit(SortClause $sortClause)
{
return $sortClause->target . $this->getDirection($sortClause);
}
}
6 changes: 6 additions & 0 deletions lib/Resources/config/search/solr/sort_clause_visitors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ services:
tags:
- {name: ezpublish.search.solr.query.content.sort_clause_visitor}
- {name: ezpublish.search.solr.query.location.sort_clause_visitor}

netgen.search.solr.query.common.sort_clause_visitor.custom_field:
class: Netgen\EzPlatformSearchExtra\Core\Search\Solr\Query\Common\SortClauseVisitor\CustomField
tags:
- {name: ezpublish.search.solr.query.content.sort_clause_visitor}
- {name: ezpublish.search.solr.query.location.sort_clause_visitor}

0 comments on commit 622139f

Please sign in to comment.