Skip to content
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

Orion-15.18.0-PLAT-10708 duration type support for query esearch adpater #9200

Merged
merged 2 commits into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions alpha/lib/enums/durationType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* @package Core
* @subpackage model.enum
*/
interface durationType extends BaseEnum
{
const ENTRY_DURATION_TYPE_NOTAVAILABLE = "notavailable";
ZurPHP marked this conversation as resolved.
Show resolved Hide resolved
const ENTRY_DURATION_TYPE_SHORT = "short";
ZurPHP marked this conversation as resolved.
Show resolved Hide resolved
const ENTRY_DURATION_TYPE_MEDIUM = "medium";
const ENTRY_DURATION_TYPE_LONG = "long";
}
7 changes: 1 addition & 6 deletions alpha/lib/model/entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ class entry extends Baseentry implements ISyncableFile, IIndexable, IOwnable, IR

const MIX_EDITOR_TYPE_SIMPLE = 1;
const MIX_EDITOR_TYPE_ADVANCED = 2;

const ENTRY_DURATION_TYPE_NOTAVAILABLE = "notavailable";
const ENTRY_DURATION_TYPE_SHORT = "short";
const ENTRY_DURATION_TYPE_MEDIUM = "medium";
const ENTRY_DURATION_TYPE_LONG = "long";


const ENTRY_CATEGORY_ESCAPE = "_";
const ENTRY_CATEGORY_SEPARATOR = ",";

Expand Down
8 changes: 4 additions & 4 deletions alpha/lib/model/entryPeer.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,15 +693,15 @@ public static function prepareEntitlementCriteriaAndFilters(Criteria $criteria)
public static function getDurationType($duration)
{
if ($duration >= 0 && $duration <= 4*60)
return entry::ENTRY_DURATION_TYPE_SHORT;
return durationType::ENTRY_DURATION_TYPE_SHORT;

if ($duration > 4*60 && $duration <= 20*60)
return entry::ENTRY_DURATION_TYPE_MEDIUM;
return durationType::ENTRY_DURATION_TYPE_MEDIUM;

if ($duration > 20*60)
return entry::ENTRY_DURATION_TYPE_LONG;
return durationType::ENTRY_DURATION_TYPE_LONG;

return entry::ENTRY_DURATION_TYPE_NOTAVAILABLE;
return durationType::ENTRY_DURATION_TYPE_NOTAVAILABLE;
}

public static function getCacheInvalidationKeys()
Expand Down
6 changes: 1 addition & 5 deletions api_v3/lib/types/enums/KalturaDurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
* @package api
* @subpackage enum
*/
class KalturaDurationType extends KalturaStringEnum
class KalturaDurationType extends KalturaStringEnum implements durationType
{
const NOT_AVAILABLE = "notavailable";
const SHORT = "short";
const MEDIUM = "medium";
const LONG = "long";
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ class ESearchEntryFilterFields extends KalturaEnum
const RANK = 'rank';
const VOTES = 'votes';
const LAST_PLAYED_AT = 'last_played_at';
const DURATION_TYPE = 'duration_type';
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class ESearchEntryQueryFromFilter extends ESearchQueryFromFilter
const MODERATION_STATUS_NOT_IN_FILTER = '_notin_moderation_status';
const ID_EQUAL_FILTER = '_eq_id';
const REDIRECT_FROM_ENTRY_ID_EQUAL_FILTER = '_eq_redirect_from_entry_id';
const DURATION_TYPE_FILTER_NAME = '_matchor_duration_type';
const SHORT_DURATION_LOWER_BOUND = 0;
const SHORT_DURATION_UPPER_BOUND = 240000; // 4 minutes in ms
const MEDIUM_DURATION_UPPER_BOUND = 1200000; // 20 minutes in ms

protected static $puserFields = array(
ESearchEntryFilterFields::USER_ID,
Expand Down Expand Up @@ -71,6 +75,12 @@ class ESearchEntryQueryFromFilter extends ESearchQueryFromFilter
ESearchEntryFilterFields::RANK,
ESearchEntryFilterFields::LAST_PLAYED_AT,
ESearchEntryFilterFields::PLAYS,
ESearchEntryFilterFields::DURATION_TYPE,
);

protected static $specialFields = array(
ESearchEntryFilterFields::FREE_TEXT,
self::DURATION_TYPE_FILTER_NAME,
);

protected static $timeFields = array(
Expand All @@ -91,6 +101,11 @@ protected static function getSupportedFields()
return self::$supportedSearchFields;
}

protected static function getSpecialFields()
{
return self::$specialFields;
}

protected static $entryNestedFields = array(
ESearchMetadataFieldName::PROFILE_ID,
);
Expand Down Expand Up @@ -213,6 +228,12 @@ public function createElasticQueryFromFilter(baseObjectFilter $filter)
$this->prepareEntriesCriteriaFilter($filter);
foreach($filter->fields as $field => $fieldValue)
{
if(in_array($field, static::getSpecialFields()))
ZurPHP marked this conversation as resolved.
Show resolved Hide resolved
{
$this->handleSpecialFields($field, $fieldValue);
continue;
}

if ($field === entryFilter::ORDER && !is_null($fieldValue) && $fieldValue!= '')
{
$kEsearchOrderBy = $this->getKESearchOrderBy($fieldValue);
Expand Down Expand Up @@ -267,7 +288,6 @@ protected function splitIntoParameters($filter, $field, $fieldValue )
}

list( , $operator, $fieldName) = $fieldParts;
list($operator, $fieldName) = self::handlingFreeTextField($field, $operator, $fieldName);
if(!in_array($fieldName, static::getSupportedFields()) || is_null($fieldValue) || $fieldValue === '')
{
return null;
Expand All @@ -283,14 +303,74 @@ protected function splitIntoParameters($filter, $field, $fieldValue )
return array($operator, $fieldName, $fieldValue);
}

protected static function handlingFreeTextField($field, $operator, $fieldName)
protected function handleSpecialFields($field, $fieldValue)
{
switch ($field)
{
case self::DURATION_TYPE_FILTER_NAME:
$this->handleDurationType($field, $fieldValue);
break;
case ESearchEntryFilterFields::FREE_TEXT:
$this->handlingFreeTextField($field, $fieldValue);
break;
}

}

protected function handlingFreeTextField($field, $fieldValue)
{
if ($field === ESearchEntryFilterFields::FREE_TEXT)
if (!empty($fieldValue))
{
$operator = baseObjectFilter::IN;
$fieldName = $field;
$this->addingFieldPartIntoQuery(baseObjectFilter::IN, $field, $fieldValue);
}
}

protected function handleDurationType($field, $fieldValue)
{
if(empty($fieldValue))
{
return;
}
$searchItem = new ESearchOperator();
$searchItem->setOperator(ESearchOperatorType::OR_OP);
$durationTypeValues = explode(',', $fieldValue);
$durationTypesQueries = array();
foreach($durationTypeValues as $durationType)
{
$item = new ESearchEntryItem();
$item->setItemType(ESearchItemType::RANGE);
$item->setFieldName(ESearchEntryFieldName::LENGTH_IN_MSECS);
$range = new ESearchRange();
switch ($durationType)
{
case durationType::ENTRY_DURATION_TYPE_NOTAVAILABLE:
$range->setLessThan(self::SHORT_DURATION_LOWER_BOUND);
break;
case durationType::ENTRY_DURATION_TYPE_SHORT:
$range->setGreaterThanOrEqual(self::SHORT_DURATION_LOWER_BOUND);
$range->setLessThanOrEqual(self::SHORT_DURATION_UPPER_BOUND);
break;
case durationType::ENTRY_DURATION_TYPE_MEDIUM:
$range->setGreaterThan(self::SHORT_DURATION_UPPER_BOUND);
$range->setLessThanOrEqual(self::MEDIUM_DURATION_UPPER_BOUND);
break;
case durationType::ENTRY_DURATION_TYPE_LONG:
$range->setGreaterThan(self::MEDIUM_DURATION_UPPER_BOUND);
break;
default:
KalturaLog::debug("Undefined duration type {$durationType}.");
continue;
}

$item->setRange($range);
$durationTypesQueries[] = $item;
}

if ($durationTypesQueries)
{
$searchItem->setSearchItems($durationTypesQueries);
$this->searchItems[] = $searchItem;
}
return array($operator, $fieldName);
}

protected static function translateFieldValue($fieldName, $filter, $fieldValue)
Expand All @@ -302,12 +382,14 @@ protected static function translateFieldValue($fieldName, $filter, $fieldValue)
{
throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID, $fieldValue);
}

$fieldValue = $kuser->getId();
}
else if ($fieldName === ESearchEntryFilterFields::DURATION)
{
$fieldValue = $fieldValue * 1000;
}

return $fieldValue;
}

Expand Down