Example #1
0
 public function get($refresh = false)
 {
     $sql = "select * from site";
     if ($refresh) {
         $cache = new Cache();
         $cache->delete($sql);
     }
     $db = new DB();
     $rows = $db->query($sql, true, NN_CACHE_EXPIRY_MEDIUM);
     if ($rows === false) {
         return false;
     }
     return $this->rows2Object($rows);
 }
Example #2
0
 /**
  * Query the indexer directly.  Returns an array of the results, unless
  * there was an error in which case ``false`` is returned.  However, if
  * Sphinx returns an "invalid query" error (1064), then an empty result
  * array is returned.  Note that an empty "result array" is not the same as
  * an empty array and will instead look like::
  *
  *      array({"_totalrows": 0})
  *
  * If  ``$lookupQuery`` is an empty string, then the results returned will
  * be the data from the index--this is not guaranteed to be the most recent
  * data that is in the MySQL database.  If you absolutely need the most
  * recent data from MySQL, then ``$lookupQuery`` should be a valid SQL
  * query that has contains "releases.id IN (%s)".
  *
  * @param   string      $sphinxQuery    The raw SphinxQL query.
  * @param   string      $lookupQuery    The SQL to use to lookup the results.
  * @param   bool/int    $useCache    	The ttl to store the item in the cache.
  * @return  array|false
  */
 public function searchDirect($sphinxQuery, $lookupQuery = "", $useCache = false)
 {
     $cache = new Cache();
     if ($useCache !== false && $cache->enabled && $cache->exists($sphinxQuery)) {
         $ret = $cache->fetch($sphinxQuery);
         if ($ret !== false) {
             return $ret;
         }
     }
     // Connect to Sphinx
     $hostport = explode(":", $this->pdo->getSetting('sphinxserverhost'));
     $sdb = mysqli_connect($hostport[0], "root", "", "", $hostport[1]);
     if (!$sdb) {
         // Couldn't connect to Sphinx.
         return false;
     }
     // Get the results from Sphinx.
     $lev = error_reporting();
     error_reporting(0);
     $result = mysqli_query($sdb, $sphinxQuery);
     error_reporting($lev);
     $error = mysqli_error($sdb);
     // A 1064 error means that the query is invalid, so we don't care
     // about that.
     if ($error && mysqli_errno($sdb) != 1064) {
         // All other errors we will considered a failure.
         return false;
     }
     // Get the query metadata.
     $meta = [];
     $mresult = mysqli_query($sdb, "SHOW META");
     if (!$mresult) {
         return false;
     }
     while ($row = mysqli_fetch_row($mresult)) {
         $meta[$row[0]] = $row[1];
     }
     $results = [];
     if ($result) {
         while ($row = mysqli_fetch_assoc($result)) {
             if ($lookupQuery) {
                 // Save the IDs for a batch lookup.
                 $results[] = $row["id"];
             } else {
                 $results[] = $row;
             }
         }
     }
     if ($lookupQuery && count($results) > 0) {
         $ndb = new newznab\db\Settings();
         $sql = sprintf($lookupQuery, implode(",", $results));
         $result = $ndb->queryDirect($sql);
         if ($result) {
             $results = [];
             while ($row = $ndb->getAssocArray($result)) {
                 $results[] = $row;
             }
         }
     }
     $count = 0;
     if (count($results) > 0 && array_key_exists("total", $meta)) {
         $count = (int) $meta["total_found"];
         $results[0]["_totalrows"] = $count > MAX_MATCHES ? MAX_MATCHES : $count;
     }
     if ($useCache !== false && $cache->enabled) {
         $cache->store($sphinxQuery, $results, $useCache);
     }
     return $results;
 }
Example #3
0
 public function storeCache($key, $data)
 {
     $cache = new Cache();
     $ret = $cache->set($key, $data, 900);
     if ($ret !== false) {
         return $ret;
     }
     return false;
 }