public function getSphinxFieldType($fieldName) { $sphinxTypes = CaptionSphinxPlugin::getSphinxSchemaFields(); if (!isset($sphinxTypes[$fieldName])) { return null; } return kSphinxSearchManager::getSphinxDataType($sphinxTypes[$fieldName]); }
/** * @return string */ protected function getSphinxIndexName() { if (!is_null(kCurrentContext::$partner_id) && kCurrentContext::$partner_id !== '') { $partnerId = kCurrentContext::$partner_id; } else { $partnerId = kCurrentContext::$ks_partner_id; } $partner = PartnerPeer::retrieveByPK($partnerId); if (!$partner) { return kSphinxSearchManager::getSphinxIndexName(entryPeer::TABLE_NAME); } $partnerSearchIndex = $partner->getSearchIndex(entryPeer::TABLE_NAME, entryPeer::TABLE_NAME); return kSphinxSearchManager::getSphinxIndexName($partnerSearchIndex); }
/** * @param IIndexable $object * @return bool */ public function deleteFromSphinx(IIndexable $object) { $id = $object->getIntId(); $index = kSphinxSearchManager::getSphinxIndexName($object->getObjectIndexName()); KalturaLog::debug('Deleting sphinx document for object [' . get_class($object) . '] [' . $object->getId() . ']'); $sql = "delete from {$index} where id = {$id}"; return $this->execSphinx($sql, $object); }
/** * @return string */ protected function getSphinxIndexName() { return kSphinxSearchManager::getSphinxIndexName(CuePointPeer::TABLE_NAME); }
protected function getSphinxIndexName() { return kSphinxSearchManager::getSphinxIndexName(TagSearchPlugin::INDEX_NAME); }
public static function getSphinxSchema() { return array(kSphinxSearchManager::getSphinxIndexName(self::INDEX_NAME) => array('path' => '/sphinx/kaltura_tag_rt', 'fields' => self::getSphinxSchemaFields(), 'dict' => 'keywords', 'min_prefix_len' => self::MIN_TAG_SEARCH_LENGTH, 'enable_star' => '1')); }
$mode = 'execute'; if ($argc > 2) { $mode = $argv[2]; } $peerName = 'entryPeer'; if ($argc > 3) { $peerName = $argv[3]; } if (!in_array($mode, $availModes)) { die('Invalid mode, should be one of ' . implode(',', $availModes) . PHP_EOL); } $dbConf = kConf::getDB(); DbManager::setConfig($dbConf); DbManager::initialize(); myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL2; $sphinx = new kSphinxSearchManager(); $lastCreatedAt = null; $partnerIdField = call_user_func(array($peerName, 'translateFieldName'), 'PartnerId', BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME); $createdAtField = call_user_func(array($peerName, 'translateFieldName'), 'CreatedAt', BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME); call_user_func(array($peerName, 'setUseCriteriaFilter'), false); for (;;) { $c = new Criteria(); if ($partnerId != -1) { $c->add($partnerIdField, $partnerId); } if ($lastCreatedAt) { $c->add($createdAtField, $lastCreatedAt, Criteria::LESS_EQUAL); } $c->addDescendingOrderByColumn($createdAtField); $c->setLimit(500); $items = call_user_func(array($peerName, 'doSelect'), $c);
public function objectDeleted(BaseObject $object, BatchJob $raisedJob = null) { $sphinxSearchManager = new kSphinxSearchManager(); $sphinxSearchManager->deleteFromSphinx($object); return true; }
if ($argc > 2 && is_numeric($argv[2])) { $c->add(CaptionAssetItemPeer::PARTNER_ID, $argv[2], Criteria::EQUAL); } if ($argc > 3 && is_numeric($argv[3])) { $c->add(CaptionAssetItemPeer::ID, $argv[3], Criteria::GREATER_EQUAL); } if ($argc > 4) { CaptionAssetItemPeer::setUseCriteriaFilter((bool) $argv[4]); } $c->addAscendingOrderByColumn(CaptionAssetItemPeer::CREATED_AT); $c->addAscendingOrderByColumn(CaptionAssetItemPeer::ID); $c->setLimit(10000); $con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2); //$sphinxCon = DbManager::getSphinxConnection(); $captions = CaptionAssetItemPeer::doSelect($c, $con); $sphinx = new kSphinxSearchManager(); while (count($captions)) { foreach ($captions as $caption) { KalturaLog::log('caption_asset_id ' . $caption->getId() . ' int id[' . $caption->getIntId() . '] crc id[' . $sphinx->getSphinxId($caption) . '] last updated at [' . $caption->getUpdatedAt(null) . ']'); try { $ret = $sphinx->saveToSphinx($caption, true); } catch (Exception $e) { KalturaLog::err($e->getMessage()); exit - 1; } } $c->setOffset($c->getOffset() + count($captions)); kMemoryManager::clearMemory(); $captions = CaptionAssetItemPeer::doSelect($c, $con); } KalturaLog::log('Done. Cureent time: ' . time());
error_reporting(E_ALL); $dbConf = kConf::getDB(); DbManager::setConfig($dbConf); DbManager::initialize(); $availModes = array('gensqls', 'execute'); if ($argc < 2) { die('Usage: ' . basename(__FILE__) . ' <entry id> [<mode: ' . implode('/', $availModes) . '>]' . PHP_EOL); } $entryId = @$argv[1]; $mode = 'execute'; if ($argc > 2) { $mode = $argv[2]; } if (!in_array($mode, $availModes)) { die('Invalid mode, should be one of ' . implode(',', $availModes) . PHP_EOL); } $dbConf = kConf::getDB(); DbManager::setConfig($dbConf); DbManager::initialize(); $sphinx = new kSphinxSearchManager(); entryPeer::setUseCriteriaFilter(false); $entry = entryPeer::retrieveByPK($entryId); if ($entry) { if ($mode == 'execute') { $sphinx->saveToSphinx($entry, false, true); echo $entry->getId() . "Saved\n"; } else { print $sphinx->getSphinxSaveSql($entry, false, true) . PHP_EOL; } } echo "Done\n";
$c->add(MetadataPeer::PARTNER_ID, $argv[2], Criteria::EQUAL); } if ($argc > 3 && is_numeric($argv[3])) { $c->add(MetadataPeer::ID, $argv[3], Criteria::GREATER_EQUAL); } if ($argc > 4) { MetadataPeer::setUseCriteriaFilter((bool) $argv[4]); } // only dynamic objects are saved to sphinx for now $c->addAnd(MetadataPeer::OBJECT_TYPE, MetadataObjectType::DYNAMIC_OBJECT); $c->addAscendingOrderByColumn(MetadataPeer::UPDATED_AT); $c->addAscendingOrderByColumn(MetadataPeer::ID); $c->setLimit(10000); $con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2); $metadatas = MetadataPeer::doSelect($c, $con); $sphinx = new kSphinxSearchManager(); while (count($metadatas)) { foreach ($metadatas as $metadata) { /* @var $metadata Metadata */ KalturaLog::log('metadata id ' . $metadata->getId() . ' updated at ' . $metadata->getUpdatedAt(null)); try { $ret = $sphinx->saveToSphinx($metadata, true); } catch (Exception $e) { KalturaLog::err($e->getMessage()); exit - 1; } } $c->setOffset($c->getOffset() + count($metadatas)); kMemoryManager::clearMemory(); $metadatas = MetadataPeer::doSelect($c, $con); }
public static function getSphinxSchema() { return array(kSphinxSearchManager::getSphinxIndexName('cue_point') => array('path' => '/sphinx/kaltura_cue_point_rt', 'fields' => array('parent_id' => SphinxFieldType::RT_FIELD, 'entry_id' => SphinxFieldType::RT_FIELD, 'name' => SphinxFieldType::RT_FIELD, 'system_name' => SphinxFieldType::RT_FIELD, 'text' => SphinxFieldType::RT_FIELD, 'tags' => SphinxFieldType::RT_FIELD, 'roots' => SphinxFieldType::RT_FIELD, 'int_cue_point_id' => SphinxFieldType::RT_ATTR_BIGINT, 'cue_point_int_id' => SphinxFieldType::RT_ATTR_BIGINT, 'partner_id' => SphinxFieldType::RT_ATTR_BIGINT, 'start_time' => SphinxFieldType::RT_ATTR_BIGINT, 'end_time' => SphinxFieldType::RT_ATTR_BIGINT, 'duration' => SphinxFieldType::RT_ATTR_BIGINT, 'cue_point_status' => SphinxFieldType::RT_ATTR_BIGINT, 'cue_point_type' => SphinxFieldType::RT_ATTR_BIGINT, 'sub_type' => SphinxFieldType::RT_ATTR_BIGINT, 'kuser_id' => SphinxFieldType::RT_ATTR_BIGINT, 'partner_sort_value' => SphinxFieldType::RT_ATTR_BIGINT, 'force_stop' => SphinxFieldType::RT_ATTR_UINT, 'created_at' => SphinxFieldType::RT_ATTR_TIMESTAMP, 'updated_at' => SphinxFieldType::RT_ATTR_TIMESTAMP, 'str_entry_id' => SphinxFieldType::RT_ATTR_STRING, 'str_cue_point_id' => SphinxFieldType::RT_ATTR_STRING))); }
} $sphinxConfigurationIndexs[$index][$schemaFieldName] = $schemaFieldValue; } elseif ($schemaFieldName == 'fields') { foreach ($schemaFieldValue as $schemaSubFieldName => $schemaSubFieldValue) { if (isset($sphinxConfigurationIndexs[$index][$schemaFieldName][$schemaSubFieldName])) { throw new Exception('duplicated fields ' . $schemaFieldName . ' for index ' . $index); } $sphinxConfigurationIndexs[$index][$schemaFieldName][$schemaSubFieldName] = $schemaSubFieldValue; } } } } } foreach ($sphinxConfigurationIndexs as $sphinxIndexName => $sphinxIndexValues) { // applies default values $sphinxIndexValues = kSphinxSearchManager::getSphinxDefaultConfig($sphinxIndexValues); fwrite($sphinxConfigHandler, 'index ' . $sphinxIndexName . PHP_EOL . '{' . PHP_EOL); foreach ($sphinxIndexValues as $key => $value) { if ($key == 'fields') { foreach ($value as $fieldValue => $fieldName) { fwrite($sphinxConfigHandler, "\t" . $fieldName . "\t" . ' = ' . $fieldValue . PHP_EOL); } } else { if ($key == 'path') { $value = $baseDir . $value; } fwrite($sphinxConfigHandler, "\t" . $key . "\t" . ' = ' . $value . PHP_EOL); } } fwrite($sphinxConfigHandler, '}' . PHP_EOL); }
/** * @param IIndexable $object * @param bool $isInsert * @param bool $force * @return string|bool */ public function getSphinxSaveSql(IIndexable $object, $isInsert = false, $force = false) { $id = $object->getIntId(); if (!$id) { KalturaLog::err("Object [" . get_class($object) . "] id [" . $object->getId() . "] could not be saved to sphinx, int_id is empty"); return false; } // if(!$force && !$isInsert && !$this->saveToSphinxRequired($object)) // return false; $data = array('id' => $id); // NOTE: the order matters $dataStrings = array(); $dataInts = array(); $dataTimes = array(); $fields = $object->getIndexFieldsMap(); foreach ($fields as $field => $getterName) { $fieldType = $object->getIndexFieldType($field); $getter = "get{$getterName}"; switch ($fieldType) { case IIndexable::FIELD_TYPE_STRING: $dataStrings[$field] = $object->{$getter}(); break; case IIndexable::FIELD_TYPE_INTEGER: $dataInts[$field] = $object->{$getter}(); break; case IIndexable::FIELD_TYPE_DATETIME: $dataTimes[$field] = $object->{$getter}(null); break; } } // TODO - remove after solving the replace bug that removes all fields $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaSearchDataContributor'); $sphinxPluginsData = array(); foreach ($pluginInstances as $pluginName => $pluginInstance) { KalturaLog::debug("Loading {$pluginName} sphinx texts"); $sphinxPluginData = null; try { $sphinxPluginData = $pluginInstance->getSearchData($object); } catch (Exception $e) { KalturaLog::err($e->getMessage()); continue; } if ($sphinxPluginData) { KalturaLog::debug("Sphinx data for {$pluginName} [{$sphinxPluginData}]"); $sphinxPluginsData[] = $sphinxPluginData; } } if (count($sphinxPluginsData)) { $dataStrings['plugins_data'] = implode(',', $sphinxPluginsData); } foreach ($dataStrings as $key => $value) { $search = array("\\", "", "\n", "\r", "", "'", '"'); $replace = array("\\\\", "\\0", "\\n", "\\r", "\\Z", "\\'", '\\"'); $value = str_replace($search, $replace, $value); $data[$key] = "'{$value}'"; } foreach ($dataInts as $key => $value) { $value = (int) $value; $data[$key] = $value; } foreach ($dataTimes as $key => $value) { $value = (int) $value; $data[$key] = $value; } $values = implode(',', $data); $fields = implode(',', array_keys($data)); $index = kSphinxSearchManager::getSphinxIndexName($object->getObjectIndexName()); $command = 'insert'; if (!$isInsert) { $command = 'replace'; } return "{$command} into {$index} ({$fields}) values({$values})"; }
protected function getSphinxIndexName() { return kSphinxSearchManager::getSphinxIndexName(categoryKuserPeer::TABLE_NAME); }
/** * @return string */ protected function getSphinxIndexName() { return kSphinxSearchManager::getSphinxIndexName(EntryDistributionPeer::TABLE_NAME); }
$dbConf = kConf::getDB(); DbManager::setConfig($dbConf); DbManager::initialize(); $c = new Criteria(); if ($argc > 1 && is_numeric($argv[1])) { $c->add(TagPeer::ID, $argv[1], Criteria::GREATER_EQUAL); } if ($argc > 2 && is_numeric($argv[2])) { $c->add(TagPeer::PARTNER_ID, $argv[2], Criteria::EQUAL); } $c->addAscendingOrderByColumn(TagPeer::ID); $c->setLimit(10000); $con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2); //$sphinxCon = DbManager::getSphinxConnection(); $tags = TagPeer::doSelect($c, $con); $sphinx = new kSphinxSearchManager(); while (count($tags)) { foreach ($tags as $tag) { /* @var $tag Tag */ KalturaLog::log('tag id ' . $tag->getId() . ' tag string [' . $tag->getTag() . '] crc id[' . $sphinx->getSphinxId($tag) . ']'); try { $ret = $sphinx->saveToSphinx($tag, true); } catch (Exception $e) { KalturaLog::err($e->getMessage()); exit - 1; } } $c->setOffset($c->getOffset() + count($tags)); kMemoryManager::clearMemory(); $tags = TagPeer::doSelect($c, $con); }
if ($argc > 2 && is_numeric($argv[2])) { $c->add(entryPeer::PARTNER_ID, $argv[2], Criteria::EQUAL); } if ($argc > 3 && is_numeric($argv[3])) { $c->add(entryPeer::INT_ID, $argv[3], Criteria::GREATER_EQUAL); } if ($argc > 4) { entryPeer::setUseCriteriaFilter((bool) $argv[4]); } $c->addAscendingOrderByColumn(entryPeer::UPDATED_AT); $c->addAscendingOrderByColumn(entryPeer::ID); $c->setLimit(10000); $con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2); //$sphinxCon = DbManager::getSphinxConnection(); $entries = entryPeer::doSelect($c, $con); $sphinx = new kSphinxSearchManager(); while (count($entries)) { foreach ($entries as $entry) { KalturaLog::log('entry id ' . $entry->getId() . ' int id[' . $entry->getIntId() . '] crc id[' . $sphinx->getSphinxId($entry) . '] updated at [' . $entry->getUpdatedAt(null) . ']'); try { $ret = $sphinx->saveToSphinx($entry, true); } catch (Exception $e) { KalturaLog::err($e->getMessage()); exit - 1; } } $c->setOffset($c->getOffset() + count($entries)); kMemoryManager::clearMemory(); $entries = entryPeer::doSelect($c, $con); } KalturaLog::log('Done. Cureent time: ' . time());
protected function getSphinxIndexName() { return kSphinxSearchManager::getSphinxIndexName(kuserPeer::getOMClass(false)); }
if ($argc > 1 && is_numeric($argv[1])) { $c->add(categoryKuserPeer::UPDATED_AT, $argv[1], Criteria::GREATER_EQUAL); } if ($argc > 2 && is_numeric($argv[2])) { $c->add(categoryKuserPeer::PARTNER_ID, $argv[2], Criteria::EQUAL); } if ($argc > 3 && is_numeric($argv[3])) { $c->add(categoryKuserPeer::ID, $argv[3], Criteria::GREATER_EQUAL); } $c->addAscendingOrderByColumn(categoryKuserPeer::UPDATED_AT); $c->addAscendingOrderByColumn(categoryKuserPeer::ID); $c->setLimit(10000); $con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2); //$sphinxCon = DbManager::getSphinxConnection(); $categoryKusers = categoryKuserPeer::doSelect($c, $con); $sphinx = new kSphinxSearchManager(); while (count($categoryKusers)) { foreach ($categoryKusers as $categoryKuser) { /* @var $categoryKuser categoryKuser */ KalturaLog::log('$categoryKuser id ' . $categoryKuser->getId() . ' updated at ' . $categoryKuser->getUpdatedAt(null)); try { $ret = $sphinx->saveToSphinx($categoryKuser, true); } catch (Exception $e) { KalturaLog::err($e->getMessage()); exit - 1; } } $c->setOffset($c->getOffset() + count($categoryKusers)); kMemoryManager::clearMemory(); $categoryKusers = categoryKuserPeer::doSelect($c, $con); }
if ($argc > 2 && is_numeric($argv[2])) { $c->add(kuserPeer::PARTNER_ID, $argv[2], Criteria::EQUAL); } if ($argc > 3 && is_numeric($argv[3])) { $c->add(kuserPeer::ID, $argv[3], Criteria::GREATER_EQUAL); } if ($argc > 4) { kuserPeer::setUseCriteriaFilter((bool) $argv[4]); } $c->addAscendingOrderByColumn(kuserPeer::UPDATED_AT); $c->addAscendingOrderByColumn(kuserPeer::ID); $c->setLimit(10000); $con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2); //$sphinxCon = DbManager::getSphinxConnection(); $entries = kuserPeer::doSelect($c, $con); $sphinx = new kSphinxSearchManager(); while (count($entries)) { foreach ($entries as $entry) { /* @var $entry kuser */ KalturaLog::log('kuser id ' . $entry->getId() . ' updated at ' . $entry->getUpdatedAt(null)); try { $ret = $sphinx->saveToSphinx($entry, true); } catch (Exception $e) { KalturaLog::err($e->getMessage()); exit - 1; } } $c->setOffset($c->getOffset() + count($entries)); kMemoryManager::clearMemory(); $entries = kuserPeer::doSelect($c, $con); }
public function applyFilters() { $objectClass = $this->getIndexObjectName(); if (KalturaLog::getEnableTests()) { KalturaLog::debug('kaltura_entry_criteria ' . serialize($this)); } $this->criteriasLeft = 0; KalturaLog::debug("Applies " . count($this->filters) . " filters"); foreach ($this->filters as $index => $filter) { KalturaLog::debug("Applies filter {$index}"); $this->applyFilter(clone $filter); } // attach all default criteria from peer $objectClass::getDefaultCriteriaFilter()->applyFilter($this); if (!$this->hasAdvancedSearchFilter && !count($this->matchClause) && $this->shouldSkipSphinx() && !isset($this->groupByColumn) && !isset($this->selectColumn)) { KalturaLog::debug('Skip Sphinx'); $this->sphinxSkipped = true; return; } $fieldsToKeep = $objectClass::getSphinxConditionsToKeep(); $criterionsMap = $this->getMap(); uksort($criterionsMap, array('SphinxCriteria', 'sortFieldsByPriority')); // go over all criterions and try to move them to the sphinx foreach ($criterionsMap as $field => $criterion) { if (!$criterion instanceof SphinxCriterion) { KalturaLog::debug("Criterion [" . $criterion->getColumn() . "] is not sphinx criteria"); $this->criteriasLeft++; continue; } if ($criterion->apply($this)) { KalturaLog::debug("Criterion [" . $criterion->getColumn() . "] attached"); if (!in_array($field, $fieldsToKeep)) { $this->keyToRemove[] = $field; } } else { KalturaLog::debug("Criterion [" . $criterion->getColumn() . "] failed"); $this->criteriasLeft++; } } KalturaLog::debug("Applied " . count($this->matchClause) . " matches, " . count($this->whereClause) . " clauses, " . count($this->keyToRemove) . " keys removed, {$this->criteriasLeft} keys left"); // Adds special sphinx optimizations matches $this->addSphinxOptimizationMatches($criterionsMap); if (count($this->matchClause)) { $this->matchClause = array_unique($this->matchClause); $matches = reset($this->matchClause); if (count($this->matchClause) > 1) { $matches = '( ' . implode(' ) ( ', $this->matchClause) . ' )'; } $this->addWhere("MATCH('{$matches}')"); } $conditions = ''; $i = 0; foreach ($this->conditionClause as $conditionClause) { if ($this->conditionClause[$i] == '') { continue; } $conditions .= ', (' . $this->conditionClause[$i] . ') as cnd' . $i . ' '; $this->addWhere('cnd' . $i . ' > 0'); $i++; } $wheres = ''; KalturaLog::debug("Where clause: " . print_r($this->whereClause, true)); $this->whereClause = array_unique($this->whereClause); if (count($this->whereClause)) { $wheres = 'WHERE ' . implode(' AND ', $this->whereClause); } $orderBy = ''; $orderByColumns = $this->getOrderByColumns(); $orderByColumns = array_unique($orderByColumns); $usesWeight = false; $setLimit = true; $orders = array(); if (count($orderByColumns)) { $replace = $objectClass::getIndexOrderList(); $search = array_keys($replace); $this->clearOrderByColumns(); foreach ($orderByColumns as $orderByColumn) { $arr = explode(' ', $orderByColumn); $orderField = $arr[0]; $orderFieldParts = explode(".", $orderField); $isWeight = end($orderFieldParts) == "WEIGHT"; if (isset($replace[$orderField]) || $isWeight) { if ($isWeight) { $replace[$orderField] = "w"; $conditions .= ",weight() as w"; $usesWeight = true; $search = array_keys($replace); } KalturaLog::debug("Add sort field[{$orderField}] copy from [{$orderByColumn}]"); $orders[] = str_replace($search, $replace, $orderByColumn); } else { KalturaLog::debug("Skip sort field[{$orderField}] from [{$orderByColumn}] limit won't be used in sphinx query"); $setLimit = false; $matches = null; if (preg_match('/^\\s*([^\\s]+)\\s+(ASC|DESC)\\s*$/i', $orderByColumn, $matches)) { list($match, $column, $direction) = $matches; if (strtoupper($direction) == Criteria::DESC) { $this->addDescendingOrderByColumn($column); } else { $this->addAscendingOrderByColumn($column); } } } } } foreach ($this->orderByClause as $orderByClause) { $orders[] = $orderByClause; } if (count($orders)) { $this->applySortRequired = true; $orders = array_unique($orders); $orderBy = 'ORDER BY ' . implode(',', $orders); if (count($this->numericalOrderConditions)) { $conditions .= "," . implode(",", $this->numericalOrderConditions); } } else { $this->applySortRequired = false; } $this->ranker = self::RANKER_NONE; if ($usesWeight) { $this->ranker = self::RANKER_BM25; } $index = kSphinxSearchManager::getSphinxIndexName($objectClass::getObjectIndexName()); $maxMatches = self::getMaxRecords(); $limit = $maxMatches; if ($this->criteriasLeft) { $setLimit = false; } if ($setLimit && $this->getLimit()) { if ($this->getOffset() >= self::MAX_MATCHES) { throw new kCoreException("sphinx max matches limit was reached", kCoreException::SPHINX_CRITERIA_EXCEEDED_MAX_MATCHES_ALLOWED); } $maxMatches = min($maxMatches, $this->getLimit()); $maxMatches += $this->getOffset(); $maxMatches = min($maxMatches, self::MAX_MATCHES); $limit = $this->getLimit(); if ($this->getOffset()) { $limit = $this->getOffset() . ", {$limit}"; } } $this->executeSphinx($index, $wheres, $orderBy, $limit, $maxMatches, $setLimit, $conditions); }
public static function getSphinxSchema() { return array(kSphinxSearchManager::getSphinxIndexName('entry_distribution') => array('path' => '/sphinx/kaltura_distribution_rt', 'fields' => array('entry_id' => SphinxFieldType::RT_FIELD, 'thumb_asset_ids' => SphinxFieldType::RT_FIELD, 'flavor_asset_ids' => SphinxFieldType::RT_FIELD, 'remote_id' => SphinxFieldType::RT_FIELD, 'int_entry_id' => SphinxFieldType::RT_ATTR_BIGINT, 'entry_distribution_id' => SphinxFieldType::RT_ATTR_BIGINT, 'partner_id' => SphinxFieldType::RT_ATTR_BIGINT, 'distribution_profile_id' => SphinxFieldType::RT_ATTR_BIGINT, 'entry_distribution_status' => SphinxFieldType::RT_ATTR_BIGINT, 'dirty_status' => SphinxFieldType::RT_ATTR_BIGINT, 'sun_status' => SphinxFieldType::RT_ATTR_BIGINT, 'plays' => SphinxFieldType::RT_ATTR_BIGINT, 'views' => SphinxFieldType::RT_ATTR_BIGINT, 'error_type' => SphinxFieldType::RT_ATTR_BIGINT, 'error_number' => SphinxFieldType::RT_ATTR_BIGINT, 'created_at' => SphinxFieldType::RT_ATTR_TIMESTAMP, 'updated_at' => SphinxFieldType::RT_ATTR_TIMESTAMP, 'submitted_at' => SphinxFieldType::RT_ATTR_TIMESTAMP, 'sunrise' => SphinxFieldType::RT_ATTR_TIMESTAMP, 'sunset' => SphinxFieldType::RT_ATTR_TIMESTAMP, 'last_report' => SphinxFieldType::RT_ATTR_TIMESTAMP, 'next_report' => SphinxFieldType::RT_ATTR_TIMESTAMP, 'str_entry_id' => SphinxFieldType::RT_ATTR_STRING))); }
define('SF_DEBUG', true); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; require_once SF_ROOT_DIR . '/../infra/bootstrap_base.php'; require_once KALTURA_INFRA_PATH . DIRECTORY_SEPARATOR . "KAutoloader.php"; KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "batch", "mediaInfoParser", "*")); KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "propel", "*")); KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "plugins", "*")); KAutoloader::setClassMapFilePath('./logs/classMap.cache'); KAutoloader::register(); error_reporting(E_ALL); $dbConf = kConf::getDB(); DbManager::setConfig($dbConf); DbManager::initialize(); if ($argc !== 2) { die('pleas provide partner id as input' . PHP_EOL . 'to run script: ' . basename(__FILE__) . ' X' . PHP_EOL . 'whereas X is partner id' . PHP_EOL); } $partnerId = @$argv[1]; $dbConf = kConf::getDB(); DbManager::setConfig($dbConf); DbManager::initialize(); $sphinx = new kSphinxSearchManager(); $c = new Criteria(); $c->add(entryPeer::PARTNER_ID, $partnerId); entryPeer::setUseCriteriaFilter(false); $entries = entryPeer::doSelect($c); foreach ($entries as $entry) { usleep(100); $sphinx->saveToSphinx($entry, false, true); echo $entry->getId() . "Saved\n"; } echo "Done\n";
<?php require_once dirname(__FILE__) . '/../bootstrap.php'; $f = fopen("php://stdin", "r"); $count = 0; $sphinxMgr = new kSphinxSearchManager(); $dbConf = kConf::getDB(); DbManager::setConfig($dbConf); DbManager::initialize(); $connection = Propel::getConnection(); while ($s = trim(fgets($f))) { $sep = strpos($s, "\t") ? "\t" : " "; list($entryId, $plays, $views) = explode($sep, $s); myPartnerUtils::resetAllFilters(); entryPeer::setDefaultCriteriaFilter(); $entry = entryPeer::retrieveByPK($entryId); if (is_null($entry)) { KalturaLog::err('Couldn\'t find entry [' . $entryId . ']'); continue; } if ($entry->getViews() != $views || $entry->getPlays() != $plays) { $entry->setViews($views); $entry->setPlays($plays); KalturaLog::debug('Successfully saved entry [' . $entryId . ']'); try { // update entry without setting the updated at $updateSql = "UPDATE entry set views='{$views}',plays='{$plays}' WHERE id='{$entryId}'"; $stmt = $connection->prepare($updateSql); $stmt->execute(); $affectedRows = $stmt->rowCount(); KalturaLog::log("AffectedRows: " . $affectedRows);
public static function getSphinxSchema() { $kalturaEntryFields = array(); $searchIndexes = kConf::get('search_indexes'); foreach ($searchIndexes as $indexName => $indexLimit) { for ($i = 0; $i < $indexLimit; $i++) { $kalturaEntryFields[MetadataPlugin::getSphinxFieldName(MetadataPlugin::SPHINX_EXPENDER_FIELD_INT) . $i] = SphinxFieldType::RT_ATTR_UINT; } $sphinxSchema[kSphinxSearchManager::getSphinxIndexName($indexName)]['fields'] = $kalturaEntryFields; } return $sphinxSchema; }