示例#1
0
         list($id_list) = $db->fetch_row($result);
         $sortby = 'cache';
     }
 }
 $results = array();
 $plain = false;
 switch ($sortby) {
     case 'relevance':
         //sort by relevance
         $result = $db->query('SELECT p.content,p.id AS post_id,p.posted,i.locations,i.word FROM `#^search_index` AS i LEFT JOIN `#^posts` AS p ON p.id=i.post_id LEFT JOIN `#^topics` AS t ON t.id=p.topic_id LEFT JOIN `#^users` AS u ON u.id=p.poster WHERE i.word IN(' . implode(',', $terms) . ') AND ' . implode(' AND ', $addl_where)) or enhanced_error('Failed to get search information', true);
         while ($match = $db->fetch_assoc($result)) {
             if (isset($results[$match['post_id']])) {
                 $results[$match['post_id']]->addKeyword($match['word'], $match['locations']);
             } else {
                 $item = new SearchItem($match['content'], $match['posted'], $match['post_id']);
                 $item->addKeyword($match['word'], $match['locations']);
                 $results[$match['post_id']] = $item;
             }
         }
         usort($results, function ($m1, $m2) {
             return $m1->compareTo($m2);
         });
         if (!isset($_GET['direction']) || $_GET['direction'] == 'desc') {
             $results = array_reverse($results);
         }
         break;
     case 'posttime':
         $plain = true;
         $order = 'p.posted';
         break;
     case 'cache':