/** * @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); }
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')); }
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))); }
/** * @return string */ protected function getSphinxIndexName() { return kSphinxSearchManager::getSphinxIndexName(CaptionSearchPlugin::INDEX_NAME); }
protected function getSphinxIndexName() { return kSphinxSearchManager::getSphinxIndexName(kuserPeer::getOMClass(false)); }
/** * @return string */ protected function getSphinxIndexName() { return kSphinxSearchManager::getSphinxIndexName(EntryDistributionPeer::TABLE_NAME); }
/** * @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); }
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('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))); }
/** * @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); }
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; }