forked from Smile-SA/elasticsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
771 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Collapse/Builder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade this module to newer versions in the future. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCore | ||
* @author Richard BAYET <richard.bayet@smile.fr> | ||
* @copyright 2024 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
|
||
namespace Smile\ElasticsuiteCore\Search\Adapter\Elasticsuite\Request\Collapse; | ||
|
||
use Smile\ElasticsuiteCore\Search\Request\CollapseInterface; | ||
use Smile\ElasticsuiteCore\Search\Adapter\Elasticsuite\Request\InnerHits\Builder as InnerHitsBuilder; | ||
|
||
/** | ||
* Build the part of the ES request collapsing search results | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCore | ||
*/ | ||
class Builder | ||
{ | ||
/** | ||
* @var InnerHitsBuilder | ||
*/ | ||
private $innerHitsBuilder; | ||
|
||
/** | ||
* Builder constructor. | ||
* | ||
* @param InnerHitsBuilder $innerHitsBuilder Inner hits builder. | ||
*/ | ||
public function __construct(InnerHitsBuilder $innerHitsBuilder) | ||
{ | ||
$this->innerHitsBuilder = $innerHitsBuilder; | ||
} | ||
|
||
/** | ||
* Build the ES collapse section of the request from a Collapse | ||
* | ||
* @param CollapseInterface $collapseConfig Collapse configuration | ||
* | ||
* @return array | ||
*/ | ||
public function buildCollapse(CollapseInterface $collapseConfig) | ||
{ | ||
$collapse = [ | ||
'field' => $collapseConfig->getField(), | ||
]; | ||
|
||
$innerHits = []; | ||
foreach ($collapseConfig->getInnerHits() as $innerHitsConfig) { | ||
$innerHits[] = $this->innerHitsBuilder->buildInnerHits($innerHitsConfig); | ||
} | ||
if (!empty($innerHits)) { | ||
$collapse['inner_hits'] = $innerHits; | ||
} | ||
|
||
return $collapse; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/InnerHits/Builder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade this module to newer versions in the future. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCore | ||
* @author Richard BAYET <richard.bayet@smile.fr> | ||
* @copyright 2024 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
|
||
namespace Smile\ElasticsuiteCore\Search\Adapter\Elasticsuite\Request\InnerHits; | ||
|
||
use Smile\ElasticsuiteCore\Search\Request\InnerHitsInterface; | ||
use Smile\ElasticsuiteCore\Search\Adapter\Elasticsuite\Request\SortOrder\Builder as SortOrderBuilder; | ||
|
||
/** | ||
* Query inner hits builder. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCore | ||
*/ | ||
class Builder | ||
{ | ||
/** | ||
* @var SortOrderBuilder | ||
*/ | ||
private $sortOrderBuilder; | ||
|
||
/** | ||
* Builder constructor. | ||
* | ||
* @param SortOrderBuilder $sortOrderBuilder Sort order builder. | ||
*/ | ||
public function __construct(SortOrderBuilder $sortOrderBuilder) | ||
{ | ||
$this->sortOrderBuilder = $sortOrderBuilder; | ||
} | ||
|
||
/** | ||
* Build an inner hits definition into an ES inner hits section. | ||
* | ||
* @param InnerHitsInterface $innerHitsConfig Inner hits. | ||
* | ||
* @return array | ||
*/ | ||
public function buildInnerHits(InnerHitsInterface $innerHitsConfig) | ||
{ | ||
$innerHits = [ | ||
'name' => $innerHitsConfig->getName(), | ||
'from' => $innerHitsConfig->getFrom(), | ||
'size' => $innerHitsConfig->getSize(), | ||
]; | ||
|
||
$sortOrders = $this->sortOrderBuilder->buildSortOrders($innerHitsConfig->getSort()); | ||
if (!empty($sortOrders)) { | ||
$innerHits['sort'] = $sortOrders; | ||
} | ||
|
||
return $innerHits; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.