コード例 #1
0
 /**
  * Applies all filter fields and unset the handled fields
  * 
  * @param baseObjectFilter $filter
  */
 protected function applyFilterFields(entryFilter $filter)
 {
     if ($filter->get("_matchand_categories") !== null) {
         $filter->set("_matchand_categories_ids", $filter->categoryNamesToIds($filter->get("_matchand_categories")));
         $filter->unsetByName('_matchand_categories');
     }
     if ($filter->get("_matchor_categories") !== null) {
         $filter->set("_matchor_categories_ids", $filter->categoryNamesToIds($filter->get("_matchor_categories")));
         $filter->unsetByName('_matchor_categories');
     }
     if ($filter->get("_matchor_duration_type") !== null) {
         $filter->set("_matchor_duration_type", $filter->durationTypesToIndexedStrings($filter->get("_matchor_duration_type")));
     }
     if ($filter->get(baseObjectFilter::ORDER) === "recent") {
         $filter->set("_lte_available_from", time());
         $filter->set("_gteornull_end_date", time());
         // schedule not finished
         $filter->set(baseObjectFilter::ORDER, "-available_from");
     }
     if ($filter->get('_free_text')) {
         KalturaLog::debug('No advanced filter defined');
         $freeTexts = $filter->get('_free_text');
         $additionalConditions = array();
         if (preg_match('/^"[^"]+"$/', $freeTexts)) {
             $additionalConditions[] = $freeText;
             // fixme - only name,tags,description ?
         } else {
             if (strpos($freeTexts, baseObjectFilter::IN_SEPARATOR) > 0) {
                 str_replace(baseObjectFilter::AND_SEPARATOR, baseObjectFilter::IN_SEPARATOR, $freeTexts);
                 $freeTextsArr = explode(baseObjectFilter::IN_SEPARATOR, $freeTexts);
                 foreach ($freeTextsArr as $valIndex => $valValue) {
                     if (!is_numeric($valValue) && strlen($valValue) <= 1) {
                         unset($freeTextsArr[$valIndex]);
                     }
                 }
                 foreach ($freeTextsArr as $freeText) {
                     $additionalConditions[] = $freeText;
                     // fixme - only name,tags,description ?
                 }
             } else {
                 $freeTextsArr = explode(baseObjectFilter::AND_SEPARATOR, $freeTexts);
                 foreach ($freeTextsArr as $valIndex => $valValue) {
                     if (!is_numeric($valValue) && strlen($valValue) <= 1) {
                         unset($freeTextsArr[$valIndex]);
                     }
                 }
                 $freeTextExpr = implode(" +", $freeTextsArr);
                 $additionalConditions[] = $freeTextExpr;
                 // fixme - only name,tags,description ?
             }
         }
         if (count($additionalConditions)) {
             $this->whereClause[] = '(' . implode(' ', $additionalConditions) . ')';
         }
     }
     $filter->unsetByName('_free_text');
     foreach ($filter->fields as $field => $val) {
         if (is_null($val) || !strlen($val)) {
             //				KalturaLog::debug("Skip field[$field] value is null");
             continue;
         }
         $fieldParts = explode(baseObjectFilter::FILTER_PREFIX, $field, 3);
         if (count($fieldParts) != 3) {
             KalturaLog::debug("Skip field[{$field}] has [" . count($fieldParts) . "] parts");
             continue;
         }
         list($prefix, $operator, $fieldName) = $fieldParts;
         $fieldNamesArr = explode(baseObjectFilter::OR_SEPARATOR, $fieldName);
         if (count($fieldNamesArr) > 1) {
             $solrFieldNames = array();
             foreach ($fieldNamesArr as $fieldName) {
                 $solrField = self::getSolrFieldName($fieldName);
                 $type = self::getSolrFieldType($solrField);
                 $solrFieldNames[] = $solrField;
             }
             $solrField = '(' . implode(',', $solrFieldNames) . ')';
             $vals = array_unique(explode(baseObjectFilter::OR_SEPARATOR, $val));
             $val = implode(' ', $vals);
         } elseif (!$this->hasMatchableField($fieldName)) {
             KalturaLog::debug("Skip field[{$field}] has no matchable for name[{$fieldName}]");
             continue;
         } else {
             $solrField = self::getSolrFieldName($fieldName);
             $type = self::getSolrFieldType($solrField);
         }
         $valStr = print_r($val, true);
         KalturaLog::debug("Attach field[{$fieldName}] as solr field[{$solrField}] of type [{$type}] and comparison[{$operator}] for value[{$valStr}]");
         switch ($operator) {
             case baseObjectFilter::MULTI_LIKE_OR:
             case baseObjectFilter::MATCH_OR:
                 $vals = explode(',', $val);
                 foreach ($vals as $valIndex => $valValue) {
                     if (!is_numeric($valValue) && strlen($valValue) <= 1) {
                         unset($vals[$valIndex]);
                     }
                 }
                 if (count($vals)) {
                     $this->whereClause[] = "{$solrField}:(" . implode(" ", $vals) . ")";
                     $filter->unsetByName($field);
                 }
                 break;
             case baseObjectFilter::NOT_IN:
                 $vals = array();
                 if (is_string($val)) {
                     $vals = explode(',', $val);
                 } elseif (is_array($val)) {
                     $vals = $val;
                 }
                 foreach ($vals as $valIndex => $valValue) {
                     if (!is_numeric($valValue) && strlen($valValue) <= 1) {
                         unset($vals[$valIndex]);
                     }
                 }
                 if (count($vals)) {
                     $vals = array_slice($vals, 0, self::MAX_IN_VALUES);
                     $this->whereClause[] = "-{$solrField}:(" . implode(" ", $vals) . ")";
                     $filter->unsetByName($field);
                 }
                 break;
             case baseObjectFilter::IN:
                 $vals = array();
                 if (is_string($val)) {
                     $vals = explode(',', $val);
                 } elseif (is_array($val)) {
                     $vals = $val;
                 }
                 foreach ($vals as $valIndex => $valValue) {
                     if (!is_numeric($valValue) && strlen($valValue) <= 1) {
                         unset($vals[$valIndex]);
                     }
                 }
                 if (count($vals)) {
                     $vals = array_slice($vals, 0, self::MAX_IN_VALUES);
                     $this->whereClause[] = "{$solrField}:(" . implode(" ", $vals) . ")";
                     $filter->unsetByName($field);
                 }
                 break;
             case baseObjectFilter::EQ:
                 if (is_numeric($val) || strlen($val) > 1) {
                     $this->whereClause[] = "{$solrField}:{$val}";
                     // fixme - find exact match
                     $filter->unsetByName($field);
                 }
                 break;
             case baseObjectFilter::MULTI_LIKE_AND:
             case baseObjectFilter::MATCH_AND:
             case baseObjectFilter::LIKE:
                 $vals = explode(',', $val);
                 foreach ($vals as $valIndex => $valValue) {
                     if (!is_numeric($valValue) && strlen($valValue) <= 1) {
                         unset($vals[$valIndex]);
                     }
                 }
                 if (count($vals)) {
                     $this->whereClause[] = "{$solrField}:(+" . implode(" +", $vals) . ")";
                     $filter->unsetByName($field);
                 }
                 break;
             default:
                 KalturaLog::debug("Skip field[{$field}] has no opertaor[{$operator}]");
         }
     }
 }