コード例 #1
0
ファイル: SphinxSearchPlugin.php プロジェクト: himmelex/NTW
 /**
  * Create sphinx search engine object for the given table type.
  *
  * @param Memcached_DataObject $target
  * @param string $table
  * @param out &$search_engine SearchEngine object on output if successful
  * @ return boolean hook return
  */
 function onGetSearchEngine(Memcached_DataObject $target, $table, &$search_engine)
 {
     if (common_config('sphinx', 'enabled')) {
         if (!class_exists('SphinxClient')) {
             throw new ServerException('Sphinx PHP extension must be installed.');
         }
         $engine = new SphinxSearch($target, $table);
         if ($engine->is_connected()) {
             $search_engine = $engine;
             return false;
         }
     }
     // Sphinx disabled or disconnected
     return true;
 }
コード例 #2
0
ファイル: Releases.php プロジェクト: engine9-/newznab-tmux
    /**
     * Deletes a single release by GUID, and all the corresponding files.
     *
     * @param array        $identifiers ['g' => Release GUID(mandatory), 'id => ReleaseID(optional, pass false)]
     * @param NZB          $nzb
     * @param ReleaseImage $releaseImage
     */
    public function deleteSingle($identifiers, $nzb, $releaseImage)
    {
        // Delete NZB from disk.
        $nzbPath = $nzb->getNZBPath($identifiers['g']);
        if ($nzbPath) {
            @unlink($nzbPath);
        }
        // Delete images.
        $releaseImage->delete($identifiers['g']);
        //Delete from sphinx.
        $this->sphinxSearch->deleteRelease($identifiers, $this->pdo);
        // Delete from DB.
        $this->pdo->queryDelete(sprintf('
				DELETE r, rn, rc, uc, rf, ra, rs, rv, re
				FROM releases r
				LEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id
				LEFT OUTER JOIN releasecomment rc ON rc.releaseid = r.id
				LEFT OUTER JOIN usercart uc ON uc.releaseid = r.id
				LEFT OUTER JOIN releasefiles rf ON rf.releaseid = r.id
				LEFT OUTER JOIN releaseaudio ra ON ra.releaseid = r.id
				LEFT OUTER JOIN releasesubs rs ON rs.releaseid = r.id
				LEFT OUTER JOIN releasevideo rv ON rv.releaseid = r.id
				LEFT OUTER JOIN releaseextrafull re ON re.releaseid = r.id
				WHERE r.guid = %s', $this->pdo->escapeString($identifiers['g'])));
    }
コード例 #3
0
 /**
  * Get the results
  *
  * @return DataObjectSet
  */
 public function getResults($forumHolderID, $query, $order, $offset = 0, $limit = 10)
 {
     $query = $this->cleanQuery($query);
     // Default weights put title ahead of content, which effectively
     // puts threads ahead of posts.
     $fieldWeights = array("Title" => 5, "Content" => 1);
     // Work out what sorting method
     switch ($order) {
         case 'date':
             $mode = 'fields';
             $sortarg = array('Created' => 'DESC');
             break;
         case 'title':
             $mode = 'fields';
             $sortarg = array('Title' => 'ASC');
             break;
         default:
             // Sort by relevancy, but add the calculated age band,
             // which will push up more recent content.
             $mode = 'eval';
             $sortarg = "@relevance + _ageband";
             // Downgrade the title weighting, which will give more
             // emphasis to age.
             $fieldWeights = array("Title" => 1, "Content" => 1);
             break;
     }
     $cachekey = $query . ':' . $offset;
     if (!isset($this->search_cache[$cachekey])) {
         // Determine the classes to search. This always include
         // ForumThread and Post, since we decorated them. It also
         // includes Forum and Member if they are decorated, as
         // appropriate.
         $classes = array('ForumThread', 'Post');
         foreach (self::$extra_search_classes as $c) {
             if (Object::has_extension($c, 'SphinxSearchable')) {
                 $classes[] = $c;
             }
         }
         $this->search_cache[$cachekey] = SphinxSearch::search($classes, $query, array('start' => $offset, 'pagesize' => $limit, 'sortmode' => $mode, 'sortarg' => $sortarg, 'field_weights' => $fieldWeights));
     }
     return $this->search_cache[$cachekey]->Matches;
 }
コード例 #4
0
ファイル: resetSearchname.php プロジェクト: Jay204/nZEDb
<?php

/* This script runs the subject names through namecleaner to create a clean search name, it also recategorizes and runs the releases through namefixer.
 * Type php resetSearchname.php to see detailed info. */
require_once dirname(__FILE__) . '/../../../www/config.php';
use nzedb\db\Settings;
$pdo = new Settings();
$sphinx = new SphinxSearch();
$show = 2;
if (isset($argv[2]) && $argv[2] === 'show') {
    $show = 1;
}
if (isset($argv[1]) && $argv[1] == "full") {
    $res = $pdo->query("SELECT releases.id, releases.name, releases.fromname, releases.size, groups.name AS gname FROM releases INNER JOIN groups ON releases.group_id = groups.id");
    if (count($res) > 0) {
        echo $pdo->log->header("Going to recreate all search names, recategorize them and fix the names with namefixer, this can take a while.");
        $done = 0;
        $timestart = time();
        $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
        $rc = new ReleaseCleaning($pdo);
        foreach ($res as $row) {
            $newname = $rc->releaseCleaner($row['name'], $row['fromname'], $row['size'], $row['gname']);
            if (is_array($newname)) {
                $newname = $newname['cleansubject'];
            }
            $newname = $pdo->escapeString($newname);
            $pdo->queryExec(sprintf("UPDATE releases SET searchname = %s WHERE id = %d", $newname, $row['id']));
            $sphinx->updateReleaseSearchName($newname, $row['id']);
            $done++;
            $consoletools->overWritePrimary("Renaming:" . $consoletools->percentString($done, count($res)));
        }
コード例 #5
0
 function getSearchEngine($table)
 {
     require_once INSTALLDIR . '/lib/search_engines.php';
     static $search_engine;
     if (!isset($search_engine)) {
         $connected = false;
         if (common_config('sphinx', 'enabled')) {
             $search_engine = new SphinxSearch($this, $table);
             $connected = $search_engine->is_connected();
         }
         // unable to connect to sphinx' search daemon
         if (!$connected) {
             if ('mysql' === common_config('db', 'type')) {
                 $search_engine = new MySQLSearch($this, $table);
             } else {
                 $search_engine = new PGSearch($this, $table);
             }
         }
     }
     return $search_engine;
 }
コード例 #6
0
ファイル: AniDB.php プロジェクト: Jay204/nZEDb
 function processAnAnimeRelease($results)
 {
     $pdo = $this->pdo;
     $ri = new \ReleaseImage($this->pdo);
     if (count($results) > 0) {
         if ($this->echooutput) {
             $this->pdo->log->doEcho('Processing ' . count($results) . " anime releases.", true);
         }
         $sphinx = new \SphinxSearch();
         foreach ($results as $arr) {
             // clean up the release name to ensure we get a good chance at getting a valid filename
             $cleanFilename = $this->cleanFilename($arr['searchname']);
             // Get a release name to update the DB with, this is more than the title as it includes group size ... or worst case the same as the title
             $getReleaseName = $this->getReleaseName($arr['searchname']);
             if ($this->echooutput) {
                 $this->pdo->log->doEcho("\tProcessing Anime entitled: " . $getReleaseName['title'], true);
             }
             // get anidb number for the title of the naime
             $anidbID = $this->getanidbID($cleanFilename['title']);
             if (!$anidbID) {
                 $newTitle = $pdo->escapeString($getReleaseName['title']);
                 // no anidb ID found so set what we know and exit
                 $pdo->queryExec(sprintf('UPDATE releases SET searchname = %s, anidbid = %d, rageid = %d WHERE id = %d', $newTitle, -1, -2, $arr['id']));
                 $sphinx->updateReleaseSearchName($newTitle, $arr['id']);
                 continue;
             }
             if ($this->echooutput) {
                 $this->pdo->log->doEcho('Looking up: ' . $arr['searchname'], true);
             }
             $AniDBAPIArray = $this->getAnimeInfo($anidbID);
             if ($AniDBAPIArray['anidbid']) {
                 // if this anime is found postprocess it
                 $epno = explode('|', $AniDBAPIArray['epnos']);
                 $airdate = explode('|', $AniDBAPIArray['airdates']);
                 $episodetitle = explode('|', $AniDBAPIArray['episodetitles']);
                 // locate the episode if possible
                 for ($i = 0; $i < count($epno); $i++) {
                     if ($cleanFilename['epno'] == $epno[$i]) {
                         $offset = $i;
                         break;
                     } else {
                         $offset = -1;
                     }
                 }
                 // update the airdate if teh episode is found
                 $airdate = isset($airdate[$offset]) ? $airdate[$offset] : $AniDBAPIArray['startdate'];
                 // update the episode title if teh episdoe is found
                 $episodetitle = isset($episodetitle[$offset]) ? $episodetitle[$offset] : $cleanFilename['epno'];
                 //set the TV title to that of the episode
                 $tvtitle = $episodetitle !== 'Complete Movie' && $episodetitle !== $cleanFilename['epno'] ? $cleanFilename['epno'] . ' - ' . $episodetitle : $episodetitle;
                 if ($this->echooutput) {
                     $this->pdo->log->doEcho('- found ' . $AniDBAPIArray['anidbid'], true);
                 }
                 // lastly update the information, we also want a better readable name, AKA search name so we can use the title we cleaned
                 $newTitle = $pdo->escapeString($getReleaseName['title']);
                 $pdo->queryExec(sprintf('UPDATE releases SET searchname = %s, episode = %s, tvtitle = %s, tvairdate = %s, anidbid = %d, rageid = %d WHERE id = %d', $newTitle, $pdo->escapeString($cleanFilename['epno']), $pdo->escapeString($tvtitle), $pdo->escapeString($airdate), $AniDBAPIArray['anidbid'], -2, $arr['id']));
                 $sphinx->updateReleaseSearchName($newTitle, $arr['id']);
             } else {
                 // if the anime was not found, just simply update the search name
                 $newTitle = $pdo->escapeString($getReleaseName['title']);
                 $sphinx->updateReleaseSearchName($newTitle, $arr['id']);
                 $pdo->queryExec(sprintf('UPDATE releases SET searchname = %s, anidbid = %d WHERE id = %d', $newTitle, $AniDBAPIArray['anidbid'], $arr['id']));
             }
         }
         // foreach
         if ($this->echooutput) {
             $this->pdo->log->doEcho('Processed ' . count($results) . " anime releases.", true);
         }
     } else {
         if ($this->echooutput) {
             $this->pdo->log->doEcho($this->pdo->log->header('No anime releases to process.'));
         }
     }
 }
コード例 #7
0
ファイル: reindex.php プロジェクト: abiliojr/bettersearch
#!/usr/bin/env php
<?php 
/**
 * Use this tool to reindex your wiki
 *
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
 * @author  Abilio Marques <https://github.com/abiliojr>
 */
if (!defined('DOKU_ROOT')) {
    define('DOKU_ROOT', realpath(dirname(__FILE__) . '/../../../') . '/');
}
define('NOSESSION', 1);
require_once DOKU_ROOT . 'inc/init.php';
global $conf;
$sphinx = new SphinxSearch();
// clear the index
idx_get_indexer()->clear();
// must complete the basic indexing first
search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true));
foreach ($data as $val) {
    idx_addPage($val['id'], false, true);
}
// only now the backlinks counters in the dokuwiki index are valid
// so lets update sphinxsearch to reflect them
$pages = idx_get_indexer()->getPages();
foreach ($pages as $page) {
    $namespace = getNS($page);
    if (!$namespace) {
        $namespace = 'root';
    }
    $title = str_replace($conf['sepchar'], ' ', noNS($page));
コード例 #8
0
ファイル: ReleaseFiles.php プロジェクト: RickDB/newznab-tmux
 /**
  * Delete a releasefiles row.
  */
 public function delete($id)
 {
     $res = $this->pdo->queryExec(sprintf("DELETE FROM releasefiles WHERE releaseid = %d", $id));
     $this->sphinxSearch->updateRelease($id, $this->pdo);
     return $res;
 }
コード例 #9
0
ファイル: NameFixer.php プロジェクト: RickDB/newznab-tmux
    protected function _preFTsearchQuery($preTitle)
    {
        switch (NN_RELEASE_SEARCH_TYPE) {
            case \ReleaseSearch::SPHINX:
                $titlematch = \SphinxSearch::escapeString($preTitle);
                $join = sprintf('INNER JOIN releases_se rse ON rse.id = r.id
					WHERE rse.query = "@(name,searchname,filename) %s;mode=extended"', $titlematch);
                break;
            case ReleaseSearch::FULLTEXT:
            default:
                //Remove all non-printable chars from PreDB title
                preg_match_all('#[a-zA-Z0-9]{3,}#', $preTitle, $matches, PREG_PATTERN_ORDER);
                $titlematch = '+' . implode(' +', $matches[0]);
                $join = sprintf("INNER JOIN releasesearch rs ON rs.releaseid = r.id\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t(MATCH (rs.name) AGAINST ('%1\$s' IN BOOLEAN MODE)\n\t\t\t\t\t\t\tOR MATCH (rs.searchname) AGAINST ('%1\$s' IN BOOLEAN MODE))", $titlematch);
                break;
        }
        return $join;
    }
コード例 #10
0
ファイル: test-ReleaseCleaner.php プロジェクト: Jay204/nZEDb
$rename = false;
if ($argv[3] === 'true') {
    $rename = true;
}
require_once dirname(__FILE__) . '/../../../www/config.php';
$pdo = new Settings();
$group = $pdo->queryOneRow(sprintf('SELECT id FROM groups WHERE name = %s', $pdo->escapeString($argv[1])));
if ($group === false) {
    exit('No group with name ' . $argv[1] . ' found in the database.');
}
$releases = $pdo->query(sprintf('SELECT name, searchname, fromname, size, id FROM releases WHERE group_id = %d %s ORDER BY postdate LIMIT %d', $group['id'], $category, $argv[2]));
if (count($releases) === 0) {
    exit('No releases found in your database for group ' . $argv[1] . PHP_EOL);
}
$RC = new ReleaseCleaning($pdo);
$sphinx = new SphinxSearch();
foreach ($releases as $release) {
    $newName = $RC->releaseCleaner($release['name'], $release['fromname'], $release['size'], $argv[1]);
    if (is_array($newName)) {
        $newName = $newName['cleansubject'];
    }
    if ($newName !== $release['searchname']) {
        echo 'Old name: ' . $release['searchname'] . PHP_EOL;
        echo 'New name: ' . $newName . PHP_EOL . PHP_EOL;
        if ($rename === true) {
            $newName = $pdo->escapeString($newName);
            $pdo->queryExec(sprintf('UPDATE releases SET searchname = %s WHERE id = %d', $newName, $release['id']));
            $sphinx->updateReleaseSearchName($release['id'], $newName);
        }
    }
}
 /**
  * Save statistic by about each search query
  *
  * @param string $keywords
  * @return boolean
  */
 function insert_sphinx_stats($keywords_full)
 {
     global $wpdb, $table_prefix;
     if (is_paged() || SphinxSearch::sphinx_is_redirect_required($this->config->get_option('seo_url_all'))) {
         return;
     }
     $keywords = $this->clear_from_tags($keywords_full);
     $keywords = trim($keywords);
     $keywords_full = trim($keywords_full);
     $sql = "select status from {$table_prefix}sph_stats\n                where keywords_full = '" . $wpdb->escape($keywords_full) . "'\n                    limit 1";
     $status = $wpdb->get_var($sql);
     $status = intval($status);
     $sql = $wpdb->prepare("INSERT INTO {$table_prefix}sph_stats (keywords, keywords_full, date_added, status)\n            VALUES ( %s, %s, NOW(), %d )\n            ", $keywords, $keywords_full, $status);
     $wpdb->query($sql);
     return true;
 }