$_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]); } }
/** * Construct and send the query. Register the query in the global Sphinxql object * * @param bool GetMeta whether to fetch meta data for the executed query. Default is yes * @return SphinxqlResult object */ public function query($GetMeta = true) { $QueryStartTime = microtime(true); $this->build_query(); if (count($this->Errors) > 0) { $ErrorMsg = implode("\n", $this->Errors); $this->Sphinxql->error("Query builder found errors:\n{$ErrorMsg}"); return new SphinxqlResult(null, null, 1, $ErrorMsg); } $QueryString = $this->QueryString; $Result = $this->send_query($GetMeta); $QueryProcessTime = (microtime(true) - $QueryStartTime) * 1000; Sphinxql::register_query($QueryString, $QueryProcessTime); return $Result; }
/** * 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)]; }
/** * 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; }