/** * Queries the server for the specified search query. */ function query($query, $limit, $offset, $collections = 'all', $domains = 'all') { // 1. build the query $query = $this->_prepare($query); $lquery = '(title:(' . $query . ') ' . $this->matchType; $lquery .= ' url:(' . $query . ') ' . $this->matchType; $lquery .= ' description:(' . $query . ') ' . $this->matchType; $lquery .= ' keywords:(' . $query . ') ' . $this->matchType; $lquery .= ' body:(' . $query . '))'; // acls now... $access_list = session_allowed_access_list(); $status_list = session_allowed_status_list(); $team_list = session_allowed_teams_list(); if ($access_list[0] != 'all') { $lquery .= ' and access:(' . join(' ', $this->_quote($access_list)) . ')'; } if ($status_list[0] != 'all') { $lquery .= ' and status:(' . join(' ', $this->_quote($status_list)) . ')'; } if ($team_list[0] != 'all') { $lquery .= ' and team:(' . join(' ', $this->_quote($team_list)) . ')'; } if ($collections[0] != 'all') { $lquery .= ' and ctype:(' . join(' ', $this->_quote($collections)) . ')'; } if ($domains[0] != 'all') { $lquery .= ' and domain:(' . join(' ', $this->_quote($domains)) . ')'; } // 2. execute the query $hits = @$this->client->find($lquery); $this->total = count($hits); $res = array('rows' => array(), 'metadata' => array('hits' => $this->total, 'query' => $query, 'syntax' => $lquery)); for ($i = $offset; $i < $offset + $limit; $i++) { if (!isset($hits[$i])) { break; } $hit = $hits[$i]; $res['rows'][] = array('title' => $hit->_title, 'url' => $hit->url, 'description' => $hit->_description, 'score' => $hit->score, 'ctype' => $hit->ctype, 'domain' => $hit->domain); } return $res; }
$rex = new Rex($cgi->collection); if (!$rex->collection) { header('Location: ' . site_prefix() . '/index/cms-cpanel-action'); exit; } // get access control $struct = array_keys($rex->getStruct()); $acl = array(); if (!$struct) { $struct = array(); } else { $acl_list = session_allowed_access_list(); if (!in_array('all', $acl_list)) { foreach ($struct as $k) { if ($k == 'sitellite_access') { $acl = array('sitellite_access' => new rList('sitellite_access', session_allowed_access_list())); break; } } } } $pg = new Pager($cgi->offset, $limit); $pg->url = site_current() . '?collection=' . urlencode($cgi->collection); $res = $rex->getDeleted($limit, $cgi->offset, $acl); if (!$res) { $res = array(); $rex->total = 0; } $pg->total = $rex->total; $res2 = array(); foreach ($res as $k => $v) {
break; case 'search': $path = webfiles_request(); // assign query to cgi object and rex will see it // automatically, that's how awesome rex is // (actually, keywords is the predefined text // search facet which searches the name, display_title, // keywords and description, but not the body) // future: use sitesearch for body searching? global $cgi; $cgi->_keywords = $parameters['query']; // we'll add a few more checks for permissions to the search params as well $params = array(); $acl_list = session_allowed_access_list(); if (!in_array('all', $acl_list)) { $params['sitellite_access'] = new rList('sitellite_access', session_allowed_access_list()); } $team_list = session_allowed_teams_list(); if (!in_array('all', $team_list)) { $params['sitellite_team'] = new rList('sitellite_team', $team_list); } // perform the search $res = $rex->getStoreList($params); // build the result object $out = new StdClass(); $out->query = $parameters['query']; $out->results = count($res); $out->files = array(); foreach ($res as $row) { $info = $rex->getCurrent($row->name); unset($info->body);