function transcode_init_sphql() { // Initializes a basic SphinxqlQuery object $SphQL = new SphinxqlQuery(); $SphQL->select('groupid')->from('better_transcode')->where('logscore', 100)->where_match('FLAC', 'format')->order_by('RAND()')->limit(0, TORRENTS_PER_PAGE, TORRENTS_PER_PAGE); if (in_array($_GET['target'], array('v0', 'v2', '320'))) { // V0/V2/320 is missing $SphQL->where_match('!' . $_GET['target'], 'encoding', false); } elseif ($_GET['target'] === 'all') { // all transcodes are missing $SphQL->where_match('!(v0 | v2 | 320)', 'encoding', false); } else { // any transcode is missing $SphQL->where_match('!(v0 v2 320)', 'encoding', false); } if (!empty($_GET['search'])) { $SphQL->where_match($_GET['search'], '(groupname,artistname,year,taglist)'); } return $SphQL; }
$FormatArray = $_GET['formats']; if (count($FormatArray) !== count($Formats)) { $FormatNameArray = array(); foreach ($FormatArray as $Index => $MasterIndex) { if (isset($Formats[$MasterIndex])) { $FormatNameArray[$Index] = '"' . strtr(Sphinxql::sph_escape_string($Formats[$MasterIndex]), '-.', ' ') . '"'; } } if (count($FormatNameArray) >= 1) { $EnableNegation = true; if (!empty($_GET['formats_strict'])) { $SearchString = '(' . implode(' | ', $FormatNameArray) . ')'; } else { $SearchString = '(any | ' . implode(' | ', $FormatNameArray) . ')'; } $SphQL->where_match($SearchString, 'formatlist', false); } } } if (!empty($_GET['media'])) { $MediaArray = $_GET['media']; if (count($MediaArray) !== count($Media)) { $MediaNameArray = array(); foreach ($MediaArray as $Index => $MasterIndex) { if (isset($Media[$MasterIndex])) { $MediaNameArray[$Index] = '"' . strtr(Sphinxql::sph_escape_string($Media[$MasterIndex]), '-.', ' ') . '"'; } } if (count($MediaNameArray) >= 1) { $EnableNegation = true; if (!empty($_GET['media_strict'])) {
$SphQL->select('id, groupid, categoryid')->order_by($SortOrders[$OrderBy], $OrderWay); } $SphQL->from('torrents, delta'); $SphQLTor->select('id, groupid')->from('torrents, delta'); /** End query preparation **/ /** Start building search query **/ $Filtered = false; $EnableNegation = false; // Sphinx needs at least one positive search condition to support the NOT operator // File list searches make use of the proximity operator to ensure that all keywords match the same file if (!empty($_GET['filelist'])) { $SearchString = trim($_GET['filelist']); if ($SearchString !== '') { $SearchString = '"' . Sphinxql::sph_escape_string($_GET['filelist']) . '"~20'; $SphQL->where_match($SearchString, 'filelist', false); $SphQLTor->where_match($SearchString, 'filelist', false); $EnableNegation = true; } } // Collect all entered search terms to find out whether to enable the NOT operator $SearchWords = array(); foreach (array('artistname', 'groupname', 'recordlabel', 'cataloguenumber', 'taglist', 'remastertitle', 'remasteryear', 'remasterrecordlabel', 'remastercataloguenumber', 'encoding', 'format', 'media', 'description') as $Search) { if (!empty($_GET[$Search])) { $SearchString = trim($_GET[$Search]); if ($SearchString !== '') { $SearchWords[$Search] = array('include' => array(), 'exclude' => array()); if ($Search == 'taglist') { $SearchString = strtr($SearchString, '.', '_'); $Words = explode(',', $SearchString); } else { $Words = explode(' ', $SearchString);
} $Options = array('v0', 'v2', '320'); $Encodings = array('V0 (VBR)', 'V2 (VBR)', '320'); $EncodingKeys = array_fill_keys($Encodings, true); if ($_GET['type'] === '3') { $List = "!(v0 | v2 | 320)"; } else { $List = '!' . $Options[$_GET['type']]; if ($_GET['type'] !== '0') { $_GET['type'] = display_str($_GET['type']); } } $SphQL = new SphinxqlQuery(); $SphQL->select('id, groupid')->from('better_transcode')->where('logscore', 100)->where_match('FLAC', 'format')->where_match($List, 'encoding', false)->order_by('RAND()')->limit(0, TORRENTS_PER_PAGE, TORRENTS_PER_PAGE); if (!empty($_GET['search'])) { $SphQL->where_match($_GET['search'], '(groupname,artistname,year,taglist)'); } $SphQLResult = $SphQL->query(); $TorrentCount = $SphQLResult->get_meta('total'); if ($TorrentCount == 0) { error('No results found!'); } $Results = $SphQLResult->to_array('groupid'); $Groups = Torrents::get_groups(array_keys($Results)); $TorrentGroups = array(); foreach ($Groups as $GroupID => $Group) { if (empty($Group['Torrents'])) { unset($Groups[$GroupID]); continue; } foreach ($Group['Torrents'] as $Torrent) {