<?php

class SBBSearch {

  var $count = 0;
  var $error;
  var $success;
     
  function SBBSearch() {
    global $board_config;
    $this->auth = $SBBAuth;
    $this->board_config = $board_config;
    $this->per_page = $board_config->results_per_page;
  }
  
  function GetStringResults($q) {
    //search within questions
    $sql = "select unix_timestamp(datetime) as ut, topic, 'q' as type, detail as message, uid, id as tid, fid, name from `" . $this->board_config->prefix . "question` where topic like " . dbquote("%$q%") . " or detail like " . dbquote("%$q%") . " order by datetime limit 1000";
    $res = dbquery($sql);
    $x = 1000;
    while ($row = mysql_fetch_object($res)) {
      $x++;
      $posts[$row->ut . "_$x"]["content"] = $row;
      $posts[$row->ut . "_$x"]["type"] = "question";
      $keys[] = $row->ut . "_$x";
    }
    //search within answers
    $sql = "select unix_timestamp(`" . $this->board_config->prefix . "answer`.a_datetime) as ut, 'a' as type, `" . $this->board_config->prefix . "answer`.a_name as name, topic, a_topic, a_answer as message, `" . $this->board_config->prefix . "answer`.a_uid as uid, a_id, question_id as tid, fid from `" . $this->board_config->prefix . "answer`, `" . $this->board_config->prefix . "question` where (`" . $this->board_config->prefix . "answer`.a_topic like " . dbquote("%$q%") . " or `" . $this->board_config->prefix . "answer`.a_answer like " . dbquote("%$q%") . ") and `" . $this->board_config->prefix . "answer`.question_id = `" . $this->board_config->prefix . "question`.id";
    $res = dbquery($sql);
    if (mysql_num_rows($res)) {
      while ($row = mysql_fetch_object($res)) {
        $x++;
        $posts[$row->ut . "_$x"]["content"] = $row;
        $keys[] = $row->ut . "_$x";
      }
    }
    return array("keys" => $keys,
                 "posts" => $posts);
  }
}

?>