Example #1
0
 public static function run($scope, $query)
 {
     self::$enterprise = 'enterprise' === $scope;
     if (' ' !== $query[0]) {
         return '';
     }
     $query = ltrim($query);
     self::$query = $query;
     self::$parts = $parts = explode(' ', $query);
     Workflow::init(self::$enterprise, $query);
     if (Workflow::checkUpdate()) {
         self::addUpdateCommands();
         return Workflow::getItemsAsXml();
     }
     if (self::$enterprise && !Workflow::getBaseUrl()) {
         self::addEnterpriseUrlCommand();
         return Workflow::getItemsAsXml();
     }
     if (!Workflow::getAccessToken() || !(self::$user = Workflow::requestApi('/user'))) {
         self::addLoginCommands();
         return Workflow::getItemsAsXml();
     }
     Workflow::stopServer();
     $isSystem = isset($query[0]) && $query[0] == '>';
     $isMy = 'my' == $parts[0] && isset($parts[1]);
     $isUser = isset($query[0]) && $query[0] == '@';
     $isRepo = false;
     $queryUser = null;
     if ($isUser) {
         $queryUser = ltrim($parts[0], '@');
     } elseif (($pos = strpos($parts[0], '/')) !== false) {
         $queryUser = substr($parts[0], 0, $pos);
         $isRepo = true;
     }
     if ($isSystem) {
         self::addSystemCommands();
         Workflow::sortItems();
     } else {
         if ($isMy) {
             self::addMyCommands();
         } elseif ($isUser && isset($parts[1])) {
             self::addUserSubCommands($queryUser);
         } elseif (!$isUser && $isRepo && isset($parts[1])) {
             self::addRepoSubCommands();
         } else {
             self::addDefaultCommands($isUser, $isRepo, $queryUser);
         }
         Workflow::sortItems();
         if ($query) {
             if (!$isUser && $isRepo && isset($parts[1])) {
                 $repoQuery = substr($query, strlen($parts[0]) + 1);
                 Workflow::addItem(Item::create()->title("Search '{$parts['0']}' for '{$repoQuery}'")->icon('search')->arg('/' . $parts[0] . '/search?q=' . urlencode($repoQuery))->autocomplete(false), false);
             }
             $path = $isUser ? $queryUser : '******' . urlencode($query);
             $name = self::$enterprise ? 'GitHub Enterprise' : 'GitHub';
             Workflow::addItem(Item::create()->title("Search {$name} for '{$query}'")->icon('search')->arg('/' . $path)->autocomplete(false), false);
         }
     }
     return Workflow::getItemsAsXml();
 }
Example #2
0
 public function indexAction()
 {
     $key = $this->getRequest()->get('kw');
     $orderby = $this->getRequest()->get('od');
     $page = $this->getRequest()->get('page', 1);
     // $router = \Yaf\Dispatcher::getInstance()->getRouter();
     // $config = \Yaf\Application::app()->getConfig();
     $search = new Search();
     $search->setQ($key);
     $search->setPage($page);
     if (!empty($orderby)) {
         $search->setSortby($orderby);
     }
     $res = $search->query();
     $pages = 1;
     $films = null;
     if ($res) {
         $pages = empty($res['pages']) ? 1 : $res['pages'];
         if (isset($res['matches'])) {
             foreach ($res['matches'] as $match) {
                 $ids[] = $match['id'];
             }
             $conn = new MyPDO();
             $films = $conn->table('film')->select('*')->where('id in (' . implode(',', $ids) . ')')->orderBy('order by find_in_set (id, \'' . implode(',', $ids) . '\')')->execute();
         }
     }
     $this->_view->assign('films', $films);
     $this->_view->assign('kw', $key);
     $this->_view->assign('orderby', $orderby);
     $this->_view->assign('page', $page);
     $this->_view->assign('pages', $pages);
 }
Example #3
0
 /**
  * Search with solr & prepare data for output
  *
  * @param $p options
  * @param $prepare bool
  */
 private function solrSearch($p, $prepare = false)
 {
     // skip grid params
     unset($p->grid);
     $p->fl = 'id, pid, path, name, template_type, system, ' . 'size, date, date_end, oid, cid, cdate, uid, udate, case_id, acl_count, ' . 'case, template_id, task_u_assignee, status, task_d_closed, versions, ' . 'case_violation_resolved, case_violation_unresolved, cfg, type, nid, ' . 'search_hash, case_hash';
     $s = new Search();
     return $s->query($p);
 }
Example #4
0
 public function index($arguments)
 {
     Layout::set('title', 'Search');
     if (empty($_POST['query'])) {
         return Error::set('No search query found.');
     }
     $query = substr(trim(htmlentities($_POST['query'], ENT_QUOTES, 'ISO8859-1', false)), 0, 250);
     $results = Search::query($query);
     if ($results['hits']['total'] == 0) {
         return Error::set('No results found.');
     }
     $this->view['results'] = array();
     $news = new news(ConnectionFactory::get('mongo'));
     $articles = new articles(ConnectionFactory::get('mongo'));
     $lectures = new lectures(ConnectionFactory::get('mongo'));
     $i = 1;
     if (empty($results['hits']['hits'])) {
         return;
     }
     foreach ($results['hits']['hits'] as $result) {
         $entry = $result['_source'];
         switch ($entry['type']) {
             case 'news':
                 $post = $news->get($result['_id'], false, true);
                 if (empty($post)) {
                     continue;
                 }
                 $post['type'] = 'news';
                 array_push($this->view['results'], $post);
                 break;
             case 'article':
                 $article = $articles->get($result['_id'], false, true);
                 if (empty($article)) {
                     continue;
                 }
                 $article['type'] = 'article';
                 array_push($this->view['results'], $article);
                 break;
             case 'lecture':
                 $lecture = $lectures->get($result['_id'], false, true);
                 if (empty($lecture)) {
                     continue;
                 }
                 $lecture['type'] = 'lecture';
                 array_push($this->view['results'], $lecture);
                 break;
         }
         if ($i == 5) {
             break;
         }
         ++$i;
     }
 }
 public static function run($query)
 {
     self::$query = $query;
     self::$parts = $parts = explode(' ', $query);
     Workflow::init($query);
     if (Workflow::checkUpdate()) {
         self::addUpdateCommands();
         return Workflow::getItemsAsXml();
     }
     if (!Workflow::getConfig('access_token') || !(self::$user = Workflow::requestGithubApi('/user'))) {
         self::addLoginCommands();
         return Workflow::getItemsAsXml();
     }
     Workflow::stopServer();
     $isSystem = isset($query[0]) && $query[0] == '>';
     $isMy = 'my' == $parts[0] && isset($parts[1]);
     $isUser = isset($query[0]) && $query[0] == '@';
     $isRepo = false;
     $queryUser = null;
     if ($isUser) {
         $queryUser = ltrim($parts[0], '@');
     } elseif (($pos = strpos($parts[0], '/')) !== false) {
         $queryUser = substr($parts[0], 0, $pos);
         $isRepo = true;
     }
     if ($isSystem) {
         self::addSystemCommands();
         Workflow::sortItems();
     } else {
         if ($isMy) {
             self::addMyCommands();
         } elseif ($isUser && isset($parts[1])) {
             self::addUserSubCommands($queryUser);
         } elseif (!$isUser && $isRepo && isset($parts[1])) {
             self::addRepoSubCommands();
         } else {
             self::addDefaultCommands($isUser, $isRepo, $queryUser);
         }
         Workflow::sortItems();
         if ($query) {
             if (!$isUser && $isRepo && isset($parts[1])) {
                 $repoQuery = substr($query, strlen($parts[0]) + 1);
                 Workflow::addItem(Item::create()->title("Search '{$parts['0']}' for '{$repoQuery}'")->icon('search')->arg('https://github.com/' . $parts[0] . '/search?q=' . urlencode($repoQuery))->autocomplete(false), false);
             }
             $path = $isUser ? $queryUser : '******' . urlencode($query);
             Workflow::addItem(Item::create()->title("Search GitHub for '{$query}'")->icon('search')->arg('https://github.com/' . $path)->autocomplete(false), false);
         }
     }
     return Workflow::getItemsAsXml();
 }
Example #6
0
 public function results($query)
 {
     if (!empty($query)) {
         // cleanup, convert, replace, strip...
         $query = Fari_Decode::url($query);
         $query = preg_replace('~\\s{2,}~', ' ', implode(' ', explode('-', strtolower($query))));
         $query = substr($query, -1) == ' ' ? substr($query, 0, -1) : $query;
         // trailing space
         $query = substr($query, 0, 1) == ' ' ? substr($query, 1) : $query;
         // leading space
         $this->view->query = $query = Fari_Escape::alpha($query);
         $this->view->keywords = implode('-', explode(' ', $query));
         // implode back to have clean keywords
     } else {
         $this->redirect('/');
         die;
     }
     // fetch the result and add relevance to it
     $this->view->result = Search::query($query);
     $this->view->display('results');
 }
Example #7
0
function thread_post_get()
{
    global $DB;
    $Search = new Search();
    $offset = cmd(3, true) ? cmd(3, true) * 100 : 0;
    $res = $Search->query(cmd(2), "thread_post", $offset);
    $ids = array_keys($res['matches']);
    $page = cmd(3, true) + 1;
    $Query = new BoardQuery();
    $View = new BoardView();
    $View->type(VIEW_THREAD_SEARCH);
    $View->title("Search Thread Posts: " . htmlentities(cmd(2)));
    $View->subtitle(number_format($res['total']) . " results found showing " . ($offset ? $offset : 1) . "-" . ($offset + 100) . SPACE . ARROW_RIGHT . SPACE . "page: {$page}");
    $View->header(false);
    require_once DIR . "module/search/.content/main.php";
    $View->header_menu();
    if ($res['total'] == 0) {
        $ids = array(0);
    }
    $DB->query($Query->view_thread(false, cmd(3, true), cmd(4, true), $ids));
    $View->data($DB->load_all());
    $View->thread();
    $View->footer();
}
 public function pagelist($where, $template = null, $order = null, $under = null, $filter = null, $keyword = null, $param = "q", $inclusive = false)
 {
     $p = new \Phile\Repository\Page();
     $settings = \Phile\Registry::get('Phile_Settings');
     if ($order) {
         $settings = array_merge($settings, array('pages_order' => $order));
     }
     if (!$template) {
         $template = "pagelist-default";
         $this->templateDir = PLUGINS_DIR . "infostreams/pagelistSnippet/Templates";
     }
     $all = $p->findAll($settings);
     $list = array();
     if (is_array($where)) {
         // user provided a list of pages
         // - we obtain those from '$all' to make sure any provided sorting order is applied
         $where = array_map('trim', $where);
         foreach ($all as $p) {
             if (in_array($p->getUrl(), $where)) {
                 $list[] = $p;
             }
         }
     } else {
         // user provided a keyword, such as 'all', 'below' or 'search'
         switch ($where) {
             default:
             case "below":
             case "search":
                 $root = null;
                 if ($under) {
                     $p = new \Phile\Repository\Page();
                     $root = $p->findByPath($under);
                 }
                 // for 'search', we support providing an 'under' argument
                 if ($where == "search" && $root == null) {
                     // however, if it isn't provided, we default to searching all pages
                     $list = $all;
                     break;
                 }
                 if (!$root) {
                     $root = $this->currentPage;
                 }
                 $root_dir = dirname($root->getFilePath());
                 $inclusive = $this->isTrue($inclusive);
                 foreach ($all as $p) {
                     if (strpos($p->getFilePath(), $root_dir) !== false) {
                         if ($inclusive || !$inclusive && $p->getFilePath() != $root->getFilePath()) {
                             $list[] = $p;
                         }
                     }
                 }
                 break;
             case "all":
                 $list = $all;
                 break;
         }
         // once we have obtained a base list of pages, we can search and filter
         if ($where == "search") {
             if (array_key_exists($param, $_GET)) {
                 // retrieve the keyword so we know what to search for,
                 $keyword = urldecode($_GET[$param]);
                 // ... and then remove it from the $_GET array to make sure
                 // that we don't run the search again if we come across a page
                 // that contains another (pagelist: search) snippet.
                 //
                 // This fixes https://github.com/infostreams/pagelist-snippet/issues/4
                 unset($_GET[$param]);
                 $search = new Search($list);
                 $list = $search->query($keyword);
             } else {
                 $list = array();
             }
         }
     }
     if (!is_null($filter) && is_array($filter)) {
         // apply filter to filter by meta tag
         $filter_count = count($filter);
         foreach ($list as $i => $p) {
             $match_count = 0;
             foreach ($filter as $k => $v) {
                 // Check if each filter matches.
                 // Filters can be specified as regular expressions.
                 if (preg_match('/' . trim($v, '/') . '/', $p->getMeta()->{$k})) {
                     $match_count++;
                 }
             }
             if ($match_count != $filter_count) {
                 // if one or more filters don't match, then remove this page from the list
                 unset($list[$i]);
             }
         }
         // renumber filtered list
         $list = array_values($list);
     }
     // if the user provides a keyword to filter/search, do that now
     if (!is_null($keyword)) {
         foreach ($list as $i => $l) {
             if ($l == $this->currentPage) {
                 unset($list[$i]);
                 break;
             }
         }
         $search = new Search($list);
         $list = $search->query($keyword);
     }
     // We have now obtained the list of pages to display. Store it in a public
     // place so that we can inject it into the template rendering process by
     // intercepting the 'template_engine_registered' event in the main Plugin class.
     $this->pagelist = $list;
     // We can start rendering now, but only if the recursion protection says we're good
     if (self::$renderDepth < 3) {
         // (The recursion limit is here to make sure we don't accidentally time-out
         //  recursively rendering the same page)
         self::$renderDepth++;
         // get the template engine, and make sure we're working on an independent copy
         $templateEngine = \Phile\ServiceLocator::getService('Phile_Template');
         $clone = clone $templateEngine;
         // The template engine determines which template to use by looking at the
         // page's metadata. We create a dummy page with only one piece of metadata
         // (the name of the template file) to force the engine to use the template
         // we specify.
         $clone->setCurrentPage(new DummyPage($template));
         // now do the actual rendering and return the output
         $output = $clone->render();
         self::$renderDepth--;
         return $output;
     }
     // the recursion limit has been reached - return an empty string
     return "";
 }
    public function query($query)
    {
        $dir = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR;
        $jsonDir = $dir . "json";
        $indexDir = $dir . "index";
        // Percorre os indices
        $files = scandir($jsonDir);
        foreach ($files as $file) {
            if ($file == '.' || $file == '..') {
                continue;
            }
            $indexName = substr($file, 0, -5);
            $index = Lucene\Lucene::open($indexDir . DIRECTORY_SEPARATOR . $indexName);
            // Abre index
            $hits = $index->find($query);
            // Executa query
            // Lista resultados
            foreach ($hits as $hit) {
                $document = $hit->getDocument();
                // return a Zend\Search\Lucene\Field object
                // from the Zend\Search\Lucene\Document
                echo "<h3>" . $document->getFieldValue('url') . "</h3><br />";
                //echo "<p>" . $hit->text . "</p><br /><br />";
            }
        }
    }
}
$q = !empty($_GET['q']) ? $_GET['q'] : 'CBF';
$sc = new Search();
$sc->query($q);
    } else {
        if (!empty($_GET["location"])) {
            $title = $_GET["location"];
        } else {
            if (!empty($_GET["date"])) {
                $title = $_GET["date"];
            } else {
                if (!empty($_GET["user"])) {
                    $title = $_GET["user"];
                }
            }
        }
    }
}
try {
    $Search->setInclude($_GET["q"]);
    $Search->setTags($_GET["tags"]);
    $Search->setLocation($_GET["location"]);
    $Search->setDate($_GET["date"]);
    $Search->setUser($_GET["user"]);
} catch (Exception $e) {
    echo $e->getMessage();
}
if (!isset($Feed)) {
    $Feed = new Feed($Database);
}
$eventCount = 0;
foreach ($Search->query() as $status) {
    require $baseDir . 'includes/templates/feed_box.php';
    $eventCount++;
}