This repository has been archived by the owner on Aug 13, 2019. It is now read-only.
-
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
15 changed files
with
408 additions
and
863 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace CultuurNet\UDB3\Search\ElasticSearch\Aggregation; | ||
|
||
use CultuurNet\UDB3\Language; | ||
use CultuurNet\UDB3\Search\Facet\FacetFilter; | ||
use CultuurNet\UDB3\Search\Facet\FacetNode; | ||
use CultuurNet\UDB3\Search\Facet\FacetTreeInterface; | ||
use CultuurNet\UDB3\Search\Offer\FacetName; | ||
use CultuurNet\UDB3\ValueObject\MultilingualString; | ||
use ValueObjects\StringLiteral\StringLiteral; | ||
|
||
class LabelsAggregationTransformer implements AggregationTransformerInterface | ||
{ | ||
/** | ||
* @var FacetName | ||
*/ | ||
private $facetName; | ||
|
||
public function __construct( | ||
FacetName $facetName | ||
) { | ||
$this->facetName = $facetName; | ||
} | ||
|
||
/** | ||
* @param Aggregation $aggregation | ||
* @return bool | ||
*/ | ||
public function supports(Aggregation $aggregation) | ||
{ | ||
return $aggregation->getName()->sameValueAs($this->facetName); | ||
} | ||
|
||
/** | ||
* @param Aggregation $aggregation | ||
* @return FacetTreeInterface | ||
*/ | ||
public function toFacetTree(Aggregation $aggregation) | ||
{ | ||
if (!$this->supports($aggregation)) { | ||
$name = $aggregation->getName()->toNative(); | ||
throw new \LogicException("Aggregation $name not supported for transformation."); | ||
} | ||
|
||
$nodes = []; | ||
foreach ($aggregation->getBuckets() as $bucket) { | ||
if ($bucket->getCount() == 0) { | ||
continue; | ||
} | ||
|
||
// For labels we use the bucket key for all 4 supported | ||
// languages, because labels are currently not multilingual. | ||
$translatedName = new StringLiteral($bucket->getKey()); | ||
|
||
$name = new MultilingualString( | ||
new Language('nl'), | ||
$translatedName | ||
); | ||
|
||
foreach (['fr', 'de', 'en'] as $langCode) { | ||
$name = $name->withTranslation( | ||
new Language($langCode), | ||
$translatedName | ||
); | ||
} | ||
|
||
$nodes[] = new FacetNode( | ||
$bucket->getKey(), | ||
$name, | ||
$bucket->getCount() | ||
); | ||
} | ||
|
||
return new FacetFilter($this->facetName->toNative(), $nodes); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace CultuurNet\UDB3\Search\ElasticSearch\Offer; | ||
|
||
use CultuurNet\UDB3\Language; | ||
use CultuurNet\UDB3\Search\ElasticSearch\PredefinedQueryFieldsInterface; | ||
|
||
class OfferPredefinedQueryStringFields implements PredefinedQueryFieldsInterface | ||
{ | ||
public function getPredefinedFields(Language ...$languages) | ||
{ | ||
$fields = [ | ||
'id', | ||
'labels_free_text', | ||
'terms_free_text.id', | ||
'terms_free_text.label', | ||
'performer_free_text.name', | ||
'location.id', | ||
'organizer.id', | ||
]; | ||
|
||
foreach ($languages as $language) { | ||
$langCode = $language->getCode(); | ||
$fields = array_merge( | ||
$fields, | ||
[ | ||
"name.{$langCode}", | ||
"description.{$langCode}", | ||
"address.{$langCode}.addressLocality", | ||
"address.{$langCode}.postalCode", | ||
"address.{$langCode}.streetAddress", | ||
"location.name.{$langCode}", | ||
"organizer.name.{$langCode}", | ||
] | ||
); | ||
} | ||
|
||
return $fields; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace CultuurNet\UDB3\Search\ElasticSearch; | ||
|
||
use CultuurNet\UDB3\Language; | ||
|
||
interface PredefinedQueryFieldsInterface | ||
{ | ||
/** | ||
* @param Language[] $languages | ||
* @return string[] | ||
*/ | ||
public function getPredefinedFields(Language ...$languages); | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace CultuurNet\UDB3\Search\ElasticSearch; | ||
|
||
use PHPUnit_Framework_TestCase; | ||
|
||
abstract class AbstractElasticSearchQueryBuilderTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @param $value | ||
* @return array | ||
*/ | ||
protected function expectedTextQuery($value, array $fields = []) | ||
{ | ||
$textQuery = [ | ||
'query' => $value, | ||
'default_operator' => 'AND', | ||
]; | ||
|
||
if (!empty($fields)) { | ||
$textQuery += ['fields' => $fields]; | ||
} | ||
|
||
return $textQuery; | ||
} | ||
} |
Oops, something went wrong.