Пример #1
0
    $_GET['tags_type'] = 1;
} else {
    $_GET['tags_type'] = 0;
}
if (isset($SearchWords)) {
    $QueryParts = array();
    if (!$EnableNegation && !empty($SearchWords['exclude'])) {
        $SearchWords['include'] = array_merge($SearchWords['include'], $SearchWords['exclude']);
        unset($SearchWords['exclude']);
    }
    foreach ($SearchWords['include'] as $Word) {
        $QueryParts[] = Sphinxql::sph_escape_string($Word);
    }
    if (!empty($SearchWords['exclude'])) {
        foreach ($SearchWords['exclude'] as $Word) {
            $QueryParts[] = '!' . Sphinxql::sph_escape_string(substr($Word, 1));
        }
    }
    if (!empty($QueryParts)) {
        $SearchString = implode(' ', $QueryParts);
        $SphQL->where_match($SearchString, '*', false);
    }
}
if (!empty($_GET['filter_cat'])) {
    $CategoryArray = array_keys($_GET['filter_cat']);
    if (count($CategoryArray) !== count($Categories)) {
        foreach ($CategoryArray as $Key => $Index) {
            if (!isset($Categories[$Index - 1])) {
                unset($CategoryArray[$Key]);
            }
        }
Пример #2
0
 /**
  * Add fulltext query expression. Calling multiple filter functions results in boolean AND between each condition.
  * Query expression is escaped automatically
  *
  * @param string $Expr query expression
  * @param string $Field field to match $Expr against. Default is *, which means all available fields
  * @return current SphinxqlQuery object
  */
 public function where_match($Expr, $Field = '*', $Escape = true)
 {
     if (empty($Expr)) {
         return $this;
     }
     if ($Field !== false) {
         $Field = "@{$Field} ";
     }
     if ($Escape === true) {
         $this->Expressions[] = "{$Field}" . Sphinxql::sph_escape_string($Expr);
     } else {
         $this->Expressions[] = $Field . $Expr;
     }
     return $this;
 }
Пример #3
0
 /**
  * Filters a list of include and exclude tags to be used in a Sphinx search
  * @param array $Tags An array of tags with sub-arrays 'include' and 'exclude'
  * @param boolean $EnableNegation Sphinx needs at least one positive search condition to support the NOT operator
  * @param integer $TagType Search for Any or All of these tags.
  * @return array Array keys predicate and input
  *               Predicate for a Sphinx 'taglist' query
  *               Input contains clean, aliased tags. Use it in a form instead of the user submitted string
  */
 public static function tag_filter_sph($Tags, $EnableNegation, $TagType)
 {
     $QueryParts = [];
     $Tags = Tags::remove_aliases($Tags);
     $TagList = str_replace('_', '.', implode(', ', array_merge($Tags['include'], $Tags['exclude'])));
     if (!$EnableNegation && !empty($Tags['exclude'])) {
         $Tags['include'] = array_merge($Tags['include'], $Tags['exclude']);
         unset($Tags['exclude']);
     }
     foreach ($Tags['include'] as &$Tag) {
         $Tag = Sphinxql::sph_escape_string($Tag);
     }
     if (!empty($Tags['exclude'])) {
         foreach ($Tags['exclude'] as &$Tag) {
             $Tag = '!' . Sphinxql::sph_escape_string(substr($Tag, 1));
         }
     }
     // 'All' tags
     if (!isset($TagType) || $TagType == 1) {
         $SearchWords = array_merge($Tags['include'], $Tags['exclude']);
         if (!empty($Tags)) {
             $QueryParts[] = implode(' ', $SearchWords);
         }
     } else {
         if (!empty($Tags['include'])) {
             $QueryParts[] = '( ' . implode(' | ', $Tags['include']) . ' )';
         }
         if (!empty($Tags['exclude'])) {
             $QueryParts[] = implode(' ', $Tags['exclude']);
         }
     }
     return ['input' => $TagList, 'predicate' => implode(' ', $QueryParts)];
 }
Пример #4
0
 /**
  * Use phrase boundary for file searches to make sure we don't count
  * partial hits from multiple files
  *
  * @param string $Term Given search expression
  */
 private function search_filelist($Term)
 {
     $SearchString = '"' . Sphinxql::sph_escape_string($Term) . '"~20';
     $this->SphQL->where_match($SearchString, 'filelist', false);
     $this->UsedTorrentFields['filelist'] = $SearchString;
     $this->EnableNegation = true;
     $this->Filtered = true;
 }