New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plat 9889 : Add support in eSearch aggregations #8504
Changes from all commits
07eec49
bc44b0f
bd92c19
59dcd64
79c65b3
8b67086
ce58b8f
a88dc7e
8801a98
0865a7c
28e0ca6
be57d68
9f1c660
eeb1218
d95998d
2431412
57ec449
e6d733e
14e6a3b
3517895
d12449d
92a3489
b76e10e
b0009fd
0c2df08
12e7129
9950419
7a91360
5bd1ab5
a69d456
9cb8bcd
d7ab99f
e160a3d
b928ebf
53175ea
68a7d1a
3482c16
83d86e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
/** | ||
* @package plugins.elasticSearch | ||
* @subpackage api.enum | ||
*/ | ||
|
||
class KalturaESearchCategoryAggregateByFieldName extends KalturaStringEnum | ||
{ | ||
const CATEGORY_NAME = 'category_name'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
/** | ||
* @package plugins.elasticSearch | ||
* @subpackage api.enum | ||
*/ | ||
|
||
class KalturaESearchCuePointAggregateByFieldName extends KalturaStringEnum | ||
{ | ||
const TAGS = 'tags'; | ||
const TYPE = 'type'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
/** | ||
* @package plugins.elasticSearch | ||
* @subpackage api.enum | ||
*/ | ||
|
||
class KalturaESearchEntryAggregateByFieldName extends KalturaStringEnum | ||
{ | ||
const ENTRY_TYPE = 'entry_type'; | ||
const MEDIA_TYPE = 'media_type'; | ||
const TAGS = 'tags'; | ||
const ACCESS_CONTROL_PROFILE = 'access_control_profile_id'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
/** | ||
* @package plugins.elasticSearch | ||
* @subpackage api.enum | ||
*/ | ||
|
||
class KalturaESearchMetadataAggregateByFieldName extends KalturaStringEnum | ||
{ | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/** | ||
* @package plugins.elasticSearch | ||
* @subpackage api.objects | ||
*/ | ||
|
||
class KalturaESearchAggregation extends KalturaObject | ||
{ | ||
/** | ||
* @var KalturaESearchAggregationsArray | ||
*/ | ||
public $aggregations; | ||
|
||
private static $map_between_objects = array( | ||
'aggregations', | ||
); | ||
|
||
public function getMapBetweenObjects() | ||
{ | ||
return array_merge(parent::getMapBetweenObjects(), self::$map_between_objects); | ||
} | ||
|
||
public function toObject($object_to_fill = null, $props_to_skip = array()) | ||
{ | ||
if (!$object_to_fill) | ||
$object_to_fill = new ESearchAggregations(); | ||
return parent::toObject($object_to_fill, $props_to_skip); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
/** | ||
* @package plugins.elasticSearch | ||
* @subpackage api.errors | ||
*/ | ||
|
||
class KalturaESearchAggregationErrors extends KalturaESearchErrors | ||
{ | ||
const AGGREGATION_FIELD_NAME_MUST_BE_SUPPLIED = 'AGGREGATION_FIELD_NAME_MUST_BE_SUPPLIED;;Aggregation field name must be supplied'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* @package plugins.elasticSearch | ||
* @subpackage api.objects | ||
*/ | ||
|
||
abstract class KalturaESearchAggregationItem extends KalturaObject | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
public $size; | ||
|
||
public $fieldName; | ||
|
||
private static $map_between_objects = array( | ||
'size', | ||
'fieldName' | ||
); | ||
|
||
abstract public function getFieldEnumMap(); | ||
|
||
public function getMapBetweenObjects() | ||
{ | ||
return array_merge(parent::getMapBetweenObjects(), self::$map_between_objects); | ||
} | ||
|
||
public function toObject($object_to_fill = null, $props_to_skip = array()) | ||
{ | ||
if($object_to_fill) | ||
{ | ||
$fieldEnumMap = $this->getFieldEnumMap(); | ||
if (isset($fieldEnumMap[$this->fieldName])) | ||
{ | ||
$coreFieldName = $fieldEnumMap[$this->fieldName]; | ||
$object_to_fill->setFieldName($coreFieldName); | ||
$props_to_skip[] = 'fieldName'; | ||
} | ||
} | ||
|
||
return parent::toObject($object_to_fill, $props_to_skip); | ||
} | ||
|
||
abstract public function coreToApiResponse($coreResponse, $fieldName = null); | ||
|
||
public function validateForUsage($sourceObject, $propertiesToSkip = array()) | ||
{ | ||
if(is_null($this->fieldName)) | ||
{ | ||
throw new KalturaAPIException(KalturaESearchAggregationErrors::AGGREGATION_FIELD_NAME_MUST_BE_SUPPLIED); | ||
} | ||
parent::validateForUsage($sourceObject, $propertiesToSkip); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
/** | ||
* @package plugins.elasticSearch | ||
* @subpackage api.objects | ||
*/ | ||
|
||
class KalturaESearchAggregationsArray extends KalturaTypedArray | ||
{ | ||
public function __construct() | ||
{ | ||
return parent::__construct("KalturaESearchAggregationItem"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* @package plugins.elasticSearch | ||
* @subpackage api.objects | ||
*/ | ||
|
||
|
||
class KalturaESearchCategoryAggregationItem extends KalturaESearchAggregationItem | ||
{ | ||
/** | ||
* @var KalturaESearchCategoryAggregateByFieldName | ||
*/ | ||
public $fieldName; | ||
|
||
public function toObject($object_to_fill = null, $props_to_skip = array()) | ||
{ | ||
if (!$object_to_fill) | ||
{ | ||
$object_to_fill = new ESearchCategoryAggregationItem(); | ||
} | ||
return parent::toObject($object_to_fill, $props_to_skip); | ||
} | ||
|
||
public function getFieldEnumMap() | ||
{ | ||
return array (KalturaESearchCategoryAggregateByFieldName::CATEGORY_NAME => ESearchCategoryAggregationFieldName::CATEGORY_NAME); | ||
} | ||
|
||
public function coreToApiResponse($coreResponse, $fieldName = null) | ||
{ | ||
$agg = new KalturaESearchAggregationResponseItem(); | ||
$agg->fieldName = $fieldName; | ||
$agg->name = ESearchCategoryAggregationItem::KEY; | ||
$bucketsArray = new KalturaESearchAggregationBucketsArray(); | ||
$buckets = $coreResponse[ESearchAggregations::BUCKETS]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $coreResponse should be validated. |
||
if ($buckets) | ||
{ | ||
foreach ($buckets as $bucket) | ||
{ | ||
$responseBucket = new KalturaESearchAggregationBucket(); | ||
$responseBucket->fromArray($bucket); | ||
list(,$categoryName) = elasticSearchUtils::reverseFormatCategoryNameStatus($responseBucket->value); | ||
MosheMaorKaltura marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$responseBucket->value = $categoryName; | ||
$bucketsArray[] = $responseBucket; | ||
} | ||
|
||
} | ||
$agg->buckets = $bucketsArray; | ||
return array($agg); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* @package plugins.elasticSearch | ||
* @subpackage api.objects | ||
*/ | ||
|
||
class KalturaESearchCuepointsAggregationItem extends KalturaESearchAggregationItem | ||
{ | ||
/** | ||
* @var KalturaESearchCuePointAggregateByFieldName | ||
*/ | ||
public $fieldName; | ||
|
||
public function toObject($object_to_fill = null, $props_to_skip = array()) | ||
{ | ||
if (!$object_to_fill) | ||
{ | ||
$object_to_fill = new ESearchCuepointsAggregationItem(); | ||
} | ||
return parent::toObject($object_to_fill, $props_to_skip); | ||
} | ||
|
||
public function getFieldEnumMap() | ||
{ | ||
return array( | ||
KalturaESearchCuePointAggregateByFieldName::TAGS => ESearchCuePointsAggregationFieldName::TAGS, | ||
KalturaESearchCuePointAggregateByFieldName::TYPE => ESearchCuePointsAggregationFieldName::TYPE); | ||
} | ||
|
||
public function coreToApiResponse($coreResponse, $fieldName = null) | ||
{ | ||
$agg = new KalturaESearchAggregationResponseItem(); | ||
$agg->fieldName = $fieldName; | ||
$agg->name = ESearchCuepointsAggregationItem::KEY; | ||
|
||
$bucketsArray = new KalturaESearchAggregationBucketsArray(); | ||
$buckets = $coreResponse[ESearchAggregationItem::NESTED_BUCKET][ESearchAggregations::BUCKETS]; | ||
if ($buckets) | ||
{ | ||
foreach ($buckets as $bucket) | ||
{ | ||
$responseBucket = new KalturaESearchAggregationBucket(); | ||
$responseBucket->fromArray($bucket); | ||
if($fieldName === ESearchCuePointsAggregationFieldName::TYPE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should compare $fieldName to the API enum, not to the core enum as it seems to be API since we assign it to aggs->fieldName There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking the returned value from the core. |
||
{ | ||
$responseBucket->value = kPluginableEnumsManager::coreToApi('CuePointType' ,$responseBucket->value); | ||
} | ||
$bucketsArray[] = $responseBucket; | ||
} | ||
} | ||
$agg->buckets = $bucketsArray; | ||
return array($agg); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* @package plugins.elasticSearch | ||
* @subpackage api.objects | ||
*/ | ||
|
||
|
||
class KalturaESearchEntryAggregationItem extends KalturaESearchAggregationItem | ||
{ | ||
|
||
/** | ||
* @var KalturaESearchEntryAggregateByFieldName | ||
*/ | ||
public $fieldName; | ||
|
||
|
||
public function toObject($object_to_fill = null, $props_to_skip = array()) | ||
{ | ||
if (!$object_to_fill) | ||
{ | ||
$object_to_fill = new ESearchEntryAggregationItem(); | ||
} | ||
return parent::toObject($object_to_fill, $props_to_skip); | ||
} | ||
|
||
public function getFieldEnumMap() | ||
{ | ||
return array ( | ||
KalturaESearchEntryAggregateByFieldName::ENTRY_TYPE => ESearchEntryAggregationFieldName::ENTRY_TYPE, | ||
KalturaESearchEntryAggregateByFieldName::MEDIA_TYPE => ESearchEntryAggregationFieldName::MEDIA_TYPE, | ||
KalturaESearchEntryAggregateByFieldName::TAGS => ESearchEntryAggregationFieldName::TAGS, | ||
KalturaESearchEntryAggregateByFieldName::ACCESS_CONTROL_PROFILE => ESearchEntryAggregationFieldName::ACCESS_CONTROL_PROFILE); | ||
} | ||
|
||
public function coreToApiResponse($coreResponse, $fieldName = null) | ||
{ | ||
$agg = new KalturaESearchAggregationResponseItem(); | ||
$agg->fieldName = $fieldName; | ||
$agg->name = ESearchEntryAggregationItem::KEY; | ||
$bucketsArray = new KalturaESearchAggregationBucketsArray(); | ||
$buckets = $coreResponse[ESearchAggregations::BUCKETS]; | ||
if ($buckets) | ||
{ | ||
foreach ($buckets as $bucket) | ||
{ | ||
$responseBucket = new KalturaESearchAggregationBucket(); | ||
$responseBucket->fromArray($bucket); | ||
$bucketsArray[] = $responseBucket; | ||
} | ||
} | ||
$agg->buckets = $bucketsArray; | ||
return array($agg); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why array in here? it's different from the other returns |
||
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$fieldName doesn't exists in this class