Ejemplo n.º 1
0
 }
 $cacheid .= "." . $pg;
 if (!$smarty->is_cached($template, $cacheid)) {
     $offset = ($pg - 1) * $sphinx->pageSize + 1;
     if ($offset < 1000 - $pgsize) {
         $sphinx->processQuery();
         $sphinx->sort = "score ASC, @relevance DESC, @id DESC";
         #$sphinx->sort = -1;
         #$sphinx->_getClient()->SetSortMode(SPH_SORT_EXPR,"(10-score) * @weight");
         #			if (preg_match('/^\w+$/',$sphinx->q)) {
         #				$sphinx->qoutput = $sphinx->q;
         #				$sphinx->q = "{$sphinx->q} | {$sphinx->q}*"; //rank full matches first
         #			}
         if ($fuzzy) {
             $sphinx->_getClient()->SetIndexWeights(array('gaz' => 10, 'gaz_meta' => 1));
             $ids = $sphinx->returnIds($pg, 'gaz,gaz_meta');
         } else {
             $ids = $sphinx->returnIds($pg, 'gaz');
         }
         if (!empty($ids) && count($ids)) {
             $where = "id IN(" . join(",", $ids) . ")";
             $db = NewADOConnection($GLOBALS['DSN2']);
             $limit = 25;
             $prev_fetch_mode = $ADODB_FETCH_MODE;
             $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
             $rows = $db->getAssoc("\r\n\t\t\t\tselect id,name,name_2,gr,localities,localities_2,score\r\n\t\t\t\tfrom placename_index \r\n\t\t\t\twhere {$where}\r\n\t\t\t\tlimit {$limit}");
             $results = array();
             foreach ($ids as $c => $id) {
                 $row = $rows[$id];
                 $row['id'] = $id;
                 $results[] = $row;
Ejemplo n.º 2
0
}
if (!empty($_GET['q'])) {
    if (isset($_GET['legacy']) || empty($CONF['sphinx_host'])) {
        if (strpos($_GET['q'], '!') === 0) {
            $q = $db->Quote("%" . preg_replace('/^!/', '', $_GET['q']) . "%");
            #$sql_where .= " and not (t.notes like $q or i.title like $q)";
            $sql_where .= " and not (t.notes like {$q} or i.title like {$q} or i.title2 like {$q})";
        } else {
            $q = $db->Quote("%{$_GET['q']}%");
            #$sql_where .= " and (t.notes like $q or i.title like $q)";
            $sql_where .= " and (t.notes like {$q} or i.title like {$q} or i.title2 like {$q})";
        }
    } else {
        $sphinx = new sphinxwrapper($_GET['q']);
        $sphinx->pageSize = $pgsize = 100;
        $ids = $sphinx->returnIds(1, 'tickets');
        if (!empty($ids) && count($ids)) {
            $sql_where .= " and t.gridimage_ticket_id IN(" . join(",", $ids) . ")";
        } else {
            $sql_where .= " and 0";
        }
        $smarty->assign('q', $sphinx->qclean);
    }
}
#################
# available values
$types = array('pending' => 'New Tickets', 'open' => "Open Tickets", 'closed' => "Closed Tickets", 'ongoing' => 'New or Open');
$modifers = array('recent' => 'All', '24' => "over 24 hours old", '7' => "over 7 days old");
$themes = array('any' => 'Any', 'tmod' => "on ticket I moderating/ed", 'mod' => "on images I moderated", 'comment' => "tickets I have commented on", 'suggest' => "tickets I suggested", 'all' => 'any involvement');
$variations = array('any' => 'Any', 'own' => "suggested on own images", 'comment' => "has left comment");
#################
Ejemplo n.º 3
0
         $smarty->assign('meta_description', "Geograph currently has {$square->imagecount} photos in {$square->grid_reference}, {$place_name}");
     }
 }
 $smarty->assign('mode', 'normal');
 if ($grid_ok && !empty($CONF['sphinx_host']) && (isset($_GET['takenfrom']) || isset($_GET['mentioning']))) {
     $sphinx = new sphinxwrapper();
     $sphinx->pageSize = 15;
     if (isset($_GET['takenfrom'])) {
         $ids = $sphinx->returnIdsViewpoint($square->getNatEastings(), $square->getNatNorthings(), $square->reference_index, $square->grid_reference);
         $smarty->assign('viewpoint_query', $sphinx->q);
         $viewpoint_count = 0;
         //set this to zero to suppress the prompt!
         $smarty->assign('mode', 'takenfrom');
     } else {
         $sphinx->prepareQuery("{$square->grid_reference} -grid_reference:{$square->grid_reference}");
         $ids = $sphinx->returnIds(1, "_images");
         $smarty->assign('mode', 'mentioning');
         $mention_count = 0;
         //set this to zero to suppress the prompt!
     }
     if (!empty($ids) && count($ids)) {
         $images = new ImageList();
         $images->getImagesByIdList($ids);
         $square->totalimagecount = $sphinx->resultCount;
         //otherwise, lets gether the info we need to display some thumbs
         if ($square->totalimagecount) {
             $smarty->assign_by_ref('images', $images->images);
         }
         $smarty->assign('totalimagecount', $sphinx->resultCount);
         $smarty->assign('imagecount', $sphinx->resultCount);
         if ($square->totalimagecount < 10 || $USER->registered && !empty($_GET['big'])) {
Ejemplo n.º 4
0
 $cacheid = $sphinx->q;
 $sphinx->pageSize = $pgsize = 15;
 $pg = !empty($_GET['page']) ? intval(str_replace('/', '', $_GET['page'])) : 0;
 if (empty($pg) || $pg < 1) {
     $pg = 1;
 }
 $cacheid .= "." . $pg;
 if (!$smarty->is_cached($template, $cacheid)) {
     $offset = ($pg - 1) * $sphinx->pageSize + 1;
     if (preg_match("/\\b([a-zA-Z]{1,3}) ?(\\d{2,5})[ \\.]?(\\d{2,5})\\b/", $sphinx->q, $m)) {
         $smarty->assign('gridref', $m[1] . $m[2] . $m[3]);
         $sphinx->q = " " . $sphinx->q;
     }
     if ($offset < 1000 - $pgsize) {
         $sphinx->processQuery();
         $ids = $sphinx->returnIds($pg, '_posts', 'post_time');
         if (count($ids)) {
             $where = "post_id IN(" . join(",", $ids) . ")";
             $db = NewADOConnection($GLOBALS['DSN']);
             $limit = 25;
             $prev_fetch_mode = $ADODB_FETCH_MODE;
             $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
             $rows = $db->getAssoc($sql = "\r\n\t\t\t\tselect post_id,post_text,poster_name,poster_id,\r\n\t\t\t\t\tgeobb_posts.topic_id,geobb_topics.forum_id,topic_title,topic_poster,topic_poster_name\r\n\t\t\t\tfrom geobb_posts \r\n\t\t\t\t\tinner join geobb_topics using (topic_id)\r\n\t\t\t\twhere {$where}\r\n\t\t\t\tlimit {$limit}");
             $docs = array();
             foreach ($ids as $c => $id) {
                 $row = $rows[$id];
                 $docs[$c] = strip_tags(preg_replace('/<i>.*?<\\/i>/', ' ', $row['post_text']));
             }
             $reply = $sphinx->BuildExcerpts($docs, 'post_stemmed', $sphinx->q);
             $times = array('hour' => time() - 3600, 'day' => time() - 3600 * 24, 'week' => time() - 3600 * 24 * 7, 'month' => time() - 3600 * 24 * 30, 'three months' => time() - 3600 * 24 * 90);
             $results = array();
Ejemplo n.º 5
0
        }
    } else {
        $q = trim($_GET['q']);
    }
    //temporally redirect piclens full-text search directly to sphinx
    if (isset($_GET['source']) && ($_GET['source'] == 'piclens' || $_GET['source'] == 'fist')) {
        $sphinx = new sphinxwrapper($q);
        //gets a cleaned up verion of the query (suitable for filename etc)
        $cacheid = $sphinx->q;
        $sphinx->pageSize = $pgsize = 15;
        $sphinx->processQuery();
        $pg = !empty($_GET['page']) ? intval(str_replace('/', '', $_GET['page'])) : 0;
        if (empty($pg) || $pg < 1) {
            $pg = 1;
        }
        $ids = $sphinx->returnIds($pg, '_images');
        unset($q);
    } else {
        $cacheid = getTextKey();
        $pg = 1;
        //$q is used below
    }
} elseif (isset($_GET['text'])) {
    $cacheid = getTextKey();
    $pg = 1;
    $q = $_GET['text'] . ' near (anywhere)';
}
$opt_expand = !empty($_GET['expand']) && $format != 'KML' ? 1 : 0;
if (isset($cacheid)) {
    $rssfile = $_SERVER['DOCUMENT_ROOT'] . "/rss/{$cacheid}-{$pg}-{$format}{$opt_expand}.{$extension}";
    $rss_timeout = 3600;
Ejemplo n.º 6
0
$smarty->assign('noSphinx', empty($CONF['sphinx_host']));
$template = 'finder_contributors.tpl';
if (!empty($_GET['q']) && !empty($CONF['sphinx_host'])) {
    $q = trim($_GET['q']);
    $sphinx = new sphinxwrapper($q);
    //gets a cleaned up verion of the query (suitable for filename etc)
    $cacheid = $sphinx->q;
    $sphinx->pageSize = $pgsize = 15;
    $pg = !empty($_GET['page']) ? intval(str_replace('/', '', $_GET['page'])) : 0;
    if (empty($pg) || $pg < 1) {
        $pg = 1;
    }
    $cacheid .= "." . $pg;
    if (!$smarty->is_cached($template, $cacheid)) {
        $sphinx->processQuery();
        $ids = $sphinx->returnIds($pg, 'user');
        if (count($ids)) {
            $where = "user_id IN(" . join(",", $ids) . ")";
            $db = NewADOConnection($GLOBALS['DSN']);
            $limit = 25;
            $prev_fetch_mode = $ADODB_FETCH_MODE;
            $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
            $rows = $db->getAssoc("\r\n\t\t\tselect user.user_id,nickname,realname,images\r\n\t\t\tfrom user \r\n\t\t\tleft join user_stat using (user_id)\r\n\t\t\twhere {$where}\r\n\t\t\tlimit {$limit}");
            $results = array();
            foreach ($ids as $c => $id) {
                $row = $rows[$id];
                $row['user_id'] = $id;
                $results[] = $row;
            }
            $smarty->assign_by_ref('results', $results);
            $smarty->assign("query_info", $sphinx->query_info);
    /**
     * run a standard search via sphinxsearch index
     * NOTE: $this->criteria->getSQLParts(...) needs to have been called before this function to populate sphinx criteria
     * @access private
     */
    function ExecuteSphinxRecordSet($pg)
    {
        global $CONF;
        $db = $this->_getDB();
        extract($this->criteria->sql, EXTR_PREFIX_ALL ^ EXTR_REFS, 'sql');
        $sphinx = new sphinxwrapper($this->criteria->sphinx['query']);
        $this->fullText = 1;
        $sphinx->pageSize = $this->criteria->resultsperpage + 0;
        $page = ($pg - 1) * $sphinx->pageSize;
        if ($page > 1000) {
            //todo - hard-coded 1000 needs autodetecting!
            //lets jump to the last page of 'past results'
            $pg = intval(ceil(1000 / $sphinx->pageSize));
            $this->currentPage = $pg;
        }
        //look for suggestions - this needs to be done before the filters are added - the same filters wont work on the gaz index
        if (isset($GLOBALS['smarty'])) {
            $suggestions = array();
            if (empty($this->countOnly) && $sphinx->q && strlen($sphinx->q) < 64 && empty($this->criteria->sphinx['x'])) {
                $suggestions = $sphinx->didYouMean($sphinx->q);
            } elseif ($this->criteria->searchclass == 'Placename' && strpos($this->criteria->searchdesc, $this->criteria->searchq) == FALSE && (empty($this->criteria->searchtext) || $this->criteria->searchq == $this->criteria->searchtext) && isset($GLOBALS['smarty'])) {
                $suggestions = array(array('gr' => '(anywhere)', 'localities' => 'as text search', 'query' => $this->criteria->searchq));
            }
            if (!empty($this->criteria->searchtext)) {
                if (is_numeric($this->criteria->searchtext)) {
                    require_once 'geograph/gridsquare.class.php';
                    require_once 'geograph/gridimage.class.php';
                    $image = new GridImage();
                    $image->loadFromId($this->criteria->searchtext);
                    if ($image->isValid() && ($image->moderation_status != 'rejected' && $image->moderation_status != 'pending' || $image->user_id == $GLOBALS['USER']->user_id)) {
                        $suggestions += array(array('link' => "/photo/{$image->gridimage_id}", 'gr' => '(anywhere)', 'localities' => "Image by " . htmlentities($image->realname) . ", ID: {$image->gridimage_id}", 'query' => htmlentities2($image->title)));
                    }
                } else {
                    require_once "3rdparty/spellchecker.class.php";
                    $correction = SpellChecker::Correct($this->criteria->searchtext);
                    if ($correction != $this->criteria->searchtext && levenshtein($correction, $this->criteria->searchtext) < 0.25 * strlen($correction)) {
                        $suggestions += array(array('gr' => '(anywhere)', 'localities' => '', 'query' => $correction));
                    }
                }
            }
            if (!empty($suggestions) && count($suggestions)) {
                $GLOBALS['smarty']->assign("suggestions", $suggestions);
            }
        }
        //setup the sphinx wrapper
        if (!empty($this->criteria->sphinx['sort'])) {
            $sphinx->setSort($this->criteria->sphinx['sort']);
        }
        if (empty($this->criteria->sphinx['sort']) || $this->criteria->sphinx['sort'] == '@relevance DESC, @id DESC') {
            if (preg_match('/\\w+/', preg_replace('/(@\\w+ |\\w+:)\\w+/', '', $this->criteria->sphinx['query']))) {
                $this->criteria->searchdesc = str_replace('undefined', 'relevance', $this->criteria->searchdesc);
            } elseif (strlen($this->criteria->sphinx['query'])) {
                #$this->criteria->searchdesc = str_replace(', in undefined order','',$this->criteria->searchdesc);
            }
        }
        if (!empty($this->criteria->sphinx['d'])) {
            $sphinx->setSpatial($this->criteria->sphinx);
        }
        //this step is handled internally by search and setSpatial
        //$sphinx->processQuery();
        if (!empty($CONF['fetch_on_demand'])) {
            $sphinx->upper_limit = $db->getOne("SELECT MAX(gridimage_id) FROM gridimage_search");
        }
        if (is_array($this->criteria->sphinx['filters']) && count($this->criteria->sphinx['filters'])) {
            $sphinx->addFilters($this->criteria->sphinx['filters']);
        }
        //run the sphinx search
        $ids = $sphinx->returnIds($pg, empty($this->criteria->sphinx['exact']) ? '_images' : '_images_exact');
        $this->resultCount = $sphinx->resultCount;
        $this->numberOfPages = $sphinx->numberOfPages;
        $this->maxResults = $sphinx->maxResults;
        $this->islimited = true;
        if (isset($GLOBALS['smarty']) && !empty($sphinx->res['words']) && (count($sphinx->res['words']) > 1 || !$this->resultCount)) {
            $GLOBALS['smarty']->assign("statistics", $sphinx->res['words']);
        }
        if ($this->countOnly || !$this->resultCount) {
            return 0;
        }
        if ($sql_order == ' dist_sqd ') {
            $this->sphinx_matches = $sphinx->res['matches'];
            $sql_fields = ',-1 as dist_sqd';
        }
        // fetch from database
        $id_list = implode(',', $ids);
        if ($this->noCache) {
            $sql = <<<END
/* i{$this->query_id} */ SELECT gi.*,x,y,gs.grid_reference,gi.realname as credit_realname,if(gi.realname!='',gi.realname,user.realname) as realname {$sql_fields}
FROM gridimage AS gi INNER JOIN gridsquare AS gs USING(gridsquare_id)
\tINNER JOIN user ON(gi.user_id=user.user_id)
WHERE gi.gridimage_id IN ({$id_list})
ORDER BY FIELD(gi.gridimage_id,{$id_list})
END;
        } else {
            $sql = "/* i{$this->query_id} */ SELECT gi.* {$sql_fields} FROM gridimage_search as gi WHERE gridimage_id IN ({$id_list}) ORDER BY FIELD(gi.gridimage_id,{$id_list})";
        }
        if (!empty($_GET['debug'])) {
            print "<BR><BR>{$sphinx->q}<BR><BR>{$sql}";
        }
        list($usec, $sec) = explode(' ', microtime());
        $querytime_before = (double) $usec + (double) $sec;
        $recordSet =& $db->Execute($sql);
        list($usec, $sec) = explode(' ', microtime());
        $querytime_after = (double) $usec + (double) $sec;
        if ($this->display == 'excerpt') {
            $docs = array();
            foreach ($ids as $c => $id) {
                $row = $rows[$id];
                $docs[$c] = strip_tags(preg_replace('/<i>.*?<\\/i>/', ' ', $row['post_text']));
            }
            $reply = $sphinx->BuildExcerpts($docs, empty($this->criteria->sphinx['exact']) ? 'gridimage' : 'gi_stemmmed', $sphinx->q);
        }
        $this->querytime = $querytime_after - $querytime_before + $sphinx->query_time;
        //finish off
        if (!empty($recordSet) && empty($_GET['BBOX']) && $this->display != 'reveal') {
            $db->Execute("replace into queries_count set id = {$this->query_id},`count` = {$this->resultCount}");
        }
        return $recordSet;
    }
Ejemplo n.º 8
0
 /**
  * get image list for particular query
  */
 function getImagesBySphinx($q, $pgsize = 15, $pg = 1)
 {
     $sphinx = new sphinxwrapper($q);
     $sphinx->pageSize = $pgsize;
     $sphinx->processQuery();
     $ids = $sphinx->returnIds($pg, '_images');
     if (count($ids)) {
         $this->resultCount = $sphinx->resultCount;
         return $this->getImagesByIdList($ids);
     } else {
         return 0;
     }
 }
Ejemplo n.º 9
0
     // --------------
     $q = trim($_GET['q']);
     $sphinx = new sphinxwrapper($q);
     $sphinx->pageSize = $pgsize = 25;
     if (preg_match('/\\bp(age|)(\\d+)\\s*$/', $q, $m)) {
         $pg = intval($m[2]);
         $sphinx->q = preg_replace('/\\bp(age|)\\d+\\s*$/', '', $sphinx->q);
     }
     $extra .= "&amp;q=" . urlencode($sphinx->q);
     $title = "Matching word search [ " . htmlentities($sphinx->q) . " ]";
     #$sphinx->processQuery();
     if (isset($CONF['forums']) && empty($CONF['forums']) || $USER->user_id == 0) {
         $sphinx->qoutput = $sphinx->q;
         $sphinx->q .= " @source -themed";
     }
     $ids = $sphinx->returnIds($pg, 'content_stemmed');
     $smarty->assign("query_info", $sphinx->query_info);
     if (count($ids)) {
         $where = "content_id IN(" . join(",", $ids) . ")";
         //FIXME crash: ... IN() ...
     } else {
         $where = "0";
     }
     $resultCount = $sphinx->resultCount;
     $numberOfPages = $sphinx->numberOfPages;
     // --------------
 } elseif (isset($_GET['docs'])) {
     $where = "content.`type` = 'document'";
     $pageSize = 1000;
     $title = "Geograph Documents";
     $extra .= "&amp;docs=1";