/** * Simple Search interface * * @param string $query The raw query string * @param int $offset The starting offset for result documents * @param int $limit The maximum number of result documents to return * @param array $params key / value pairs for other query parameters (see Solr documentation), use arrays for parameter keys used more than once (e.g. facet.field) * @return sfLuceneResponse * * @throws Exception If an error occurs during the service call */ public function search($query, $offset = 0, $limit = 10, $params = array(), $method = self::METHOD_GET) { $results = parent::search($query, $offset, $limit, $params, $method); $results->sf_lucene_search = array('query' => $query, 'offset' => $offset, 'limit' => $limit, 'params' => $params, 'method' => $method); return $results; }
public function solrQuery($query, $offset = 0, $limit = 10, $params = array('wt' => 'json'), $method = Apache_Solr_Service::METHOD_GET) { $transportInstance = new Apache_Solr_HttpTransport_CurlNoReuse(); $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV); $solr = new Apache_Solr_Service($config->solr->server, $config->solr->port, $this->_getSolr(), $transportInstance); // if magic quotes is enabled then stripslashes will be needed if (get_magic_quotes_gpc() == 1) { $query = stripslashes($query); } $response = $solr->search($query, $offset, $limit, $params, $method); return $response->getRawResponse(); }
function get_search($arr = array(), $startindex = 0, $pagesize = 20) { if (!class_exists('Apache_Solr_Service', false)) { require dirname(dirname(dirname(__FILE__))) . '/lib/Third/SolrPhpClient/Apache/Solr/Service.php'; } $CommonConfig = (require dirname(dirname(dirname(dirname(__FILE__)))) . "/CommonConfig/commonConfig.php"); $solr = new Apache_Solr_Service($CommonConfig['SOLR_SEARCH_SERVER'], $CommonConfig['SOLR_PORT'], '/solr'); foreach ($arr as $key => $val) { $response = $solr->search($key . ':' . $val, $startindex, $pagesize, array('sort' => 'boost desc,time desc,score desc')); } return json_decode($response->getRawResponse(), true); }
/** * * @param Opus_SolrSearch_Query $query * @param bool $validateDocIds check document IDs coming from Solr index against database * @return Opus_SolrSearch_ResultList * @throws Opus_SolrSearch Exception If Solr server responds with an error or the response is empty. */ public function search($query, $validateDocIds = true) { /** * @var Apache_Solr_Response $solr_response */ $solr_response = null; try { $this->log->debug("query: " . $query->getQ()); $solr_response = $this->solr_server->search($query->getQ(), $query->getStart(), $query->getRows(), $this->getParams($query)); } catch (Exception $e) { $msg = 'Solr server responds with an error ' . $e->getMessage(); $this->log->err($msg); if ($e instanceof Apache_Solr_HttpTransportException) { if ($e->getResponse()->getHttpStatus() == '400') { // 400 seems to indicate org.apache.lucene.query.ParserParseException throw new Opus_SolrSearch_Exception($msg, Opus_SolrSearch_Exception::INVALID_QUERY, $e); } if ($e->getResponse()->getHttpStatus() == '404') { // 404 seems to indicate Solr server is unreachable throw new Opus_SolrSearch_Exception($msg, Opus_SolrSearch_Exception::SERVER_UNREACHABLE, $e); } } throw new Opus_SolrSearch_Exception($msg, null, $e); } if (is_null($solr_response)) { $msg = 'could not get an Apache_Solr_Response object'; $this->log->err($msg); throw new Opus_SolrSearch_Exception($msg); } $responseRenderer = new Opus_SolrSearch_ResponseRenderer($solr_response, $validateDocIds, $query->getSeriesId()); return $responseRenderer->getResultList(); }
public function search($query, $params, $offset = 0, $limit = 10) { $retval = false; $logger = APF::get_instance()->get_logger(); $response = $this->service->search($query, $offset, $limit, $params); APF::get_instance()->debug($this->service->qStr); if ($response->getHttpStatus() == 200) { if ($response->response->numFound > 0) { $retval = $response->response; } else { $logger->debug('solr query got zero doc'); } } else { $logger->debug('solr query got non-200 response'); } return $this->_objtoarray($retval); }
/** * * search by solr server * @param string $solrCoreName * @param string $query * @param string $sort * @param int $limit * @param int $num * * @return array | false */ public function search($solrCoreName, $query, $offset, $limit, $params = array()) { $solrServer = new \Apache_Solr_Service($this->solrhost, $this->port, '/solr/' . $solrCoreName); $response = $solrServer->search($query, $offset, $limit, $params); if ($response->getHttpStatus() == 200) { return $response->response; } else { return false; } }
public function execute() { global $wgRequest, $wgOut, $wgSolrHost, $wgSolrPort, $wgEnableWikiaSearchExt; if (empty($wgEnableWikiaSearchExt)) { $wgOut->addHTML("ERROR: WikiaSearch extension is disabled"); return; } $params = array(); $query = $wgRequest->getVal('q'); $sort = $wgRequest->getVal('sort'); $params['sort'] = !empty($sort) ? $sort : 'created desc'; $params['fl'] = 'title,url,html,created'; $lang = $wgRequest->getVal('uselang'); if (!empty($lang) && !empty($query)) { $query .= ' AND lang:' . strtolower($lang); } $excludeWikis = $wgRequest->getVal('exclude'); if (!empty($excludeWikis) && !empty($query)) { $excludeWikis = explode(',', $excludeWikis); foreach ($excludeWikis as $wikiDomain) { $wikiId = WikiFactory::DomainToID($wikiDomain); if (!empty($wikiId)) { $query .= ' AND !wid:' . $wikiId; } } } $namespaces = $wgRequest->getVal('ns'); if (!empty($namespaces) && !empty($query)) { $namespaces = explode(',', $namespaces); $nsQuery = ''; foreach ($namespaces as $ns) { $nsQuery .= (!empty($nsQuery) ? ' OR ' : '') . 'ns:' . $ns; } $query .= " AND ({$nsQuery})"; } $limit = $wgRequest->getVal('rows'); $limit = empty($limit) || $limit > 100 ? 15 : $limit; if (!empty($query)) { $solr = new Apache_Solr_Service($wgSolrHost, $wgSolrPort, '/solr'); try { $response = $solr->search($query, 0, $limit, $params); } catch (Exception $exception) { $wgOut->addHTML('ERROR: ' . $exception->getMessage()); } // render template $oTmpl = new EasyTemplate(dirname(__FILE__) . '/templates'); $oTmpl->set_vars(array('url' => $wgRequest->getFullRequestURL(), 'docs' => !is_null($response->response->docs) ? $response->response->docs : array(), 'dateFormat' => 'D, d M Y H:i:s O')); $wgRequest->response()->header('Cache-Control: max-age=60'); $wgRequest->response()->header('Content-Type: application/xml'); echo $oTmpl->render('results'); exit; } }
/** * * @param string $query * @param int $offset default 0 * @param int $limit default 10 * @param array $params additional array for parameters * @param string $method submit method default Apache_Solr_Service::METHOD_GET * * @return Apache_Solr_Response */ public function search($query, $offset, $limit, $params, $method) { $this->_setSolrService(); return $this->_solrService->search($query, $offset, $limit, $params, $method); }
/** * Executes the Solr query and returns the JSON response. */ function solr_proxy_main() { if (isset($_GET['solrUrl'])) { $spliturl = parse_url($_GET['solrUrl']); $host = $spliturl['host'] == 'solr.smk.dk' ? 'solr-02.smk.dk' : $spliturl['host']; $port = $spliturl['host'] == 'solr.smk.dk' ? '8080' : $spliturl['port']; $core_log = $spliturl['host'] == 'solr.smk.dk' ? 'prod_search_log' : 'preprod_search_log'; $path = explode("/", trim($spliturl['path'], '/')); $core = array_pop($path); $path = implode("/", $path); $solr = new Apache_Solr_Service($host, $port, '/' . $path . '/' . $core . '/'); //$solr = new Apache_Solr_Service('csdev-seb', 8180, '/solr-example/preprod_all_dk/'); //var_dump($solr); $solr_search_log = new Apache_Solr_Service($host, $port, '/' . $path . '/' . $core_log . '/'); //$solr_search_log = new Apache_Solr_Service('solr-02.smk.dk', 8080, '/solr/prod_search_log/'); //var_dump($solr_search_log); $document = new Apache_Solr_Document(); $q_default = "-(id_s:(*/*) AND category:collections) -(id_s:(*verso) AND category:collections)"; $fq_tag = "tag"; $fq_prev = array(); $q_prev = array(); $picture_url = ''; $numfound = 0; if (isset($_GET['prev_query'])) { $params = array(); $params['q'] = '*:*'; $keys = ''; $core = ''; //error_log($_GET['query']); // The names of Solr parameters that may be specified multiple times. $multivalue_keys = array('bf', 'bq', 'facet.date', 'facet.date.other', 'facet.field', 'facet.query', 'fq', 'pf', 'qf'); $pairs = explode('&', $_GET['prev_query']); foreach ($pairs as $pair) { if ($pair != '') { list($key, $value) = explode('=', $pair, 2); $value = urldecode($value); if (in_array($key, $multivalue_keys)) { $params[$key][] = $value; } elseif ($key == 'q') { //error_log($value); $keys = $value; } elseif ($key == 'core') { $core = "{$value}/"; } else { $params[$key] = $value; } } } // try { // $response = $solr->search($keys, $params['start'], $params['rows'], $params); // } // catch (Exception $e) { // die($e->__toString()); // } //error_log($response->getRawResponse()); //print $response->getRawResponse(); /*ררררררררר*/ $fq = array(); $q = array(); // proceed only if 'start' param was null ('start' is set when the user uses pagination in website, and we want to avoid duplication on search string) //if(!isset($params['start'])){ // process q if ($keys != '') { $q = explode(",", $keys); // remove default 'q' value if (($key = array_search($q_default, $q)) !== false) { unset($q[$key]); } array_filter($q); } // process fq if (isset($params['fq'])) { $fq = $params['fq']; // remove 'tag' facet $matches = array_filter($fq, function ($var) use($fq_tag) { return preg_match("/\\b{$fq_tag}\\b/i", $var); }); foreach ($matches as $key => $value) { unset($fq[$key]); } array_filter($fq); } if (count($q) + count($fq) > 0) { $fq_prev = $fq; $q_prev = $q; } //} } if (isset($_GET['query'])) { $params = array(); $params['q'] = '*:*'; $keys = ''; $core = ''; //error_log($_GET['query']); // The names of Solr parameters that may be specified multiple times. $multivalue_keys = array('bf', 'bq', 'facet.date', 'facet.date.other', 'facet.field', 'facet.query', 'fq', 'pf', 'qf'); $pairs = explode('&', $_GET['query']); foreach ($pairs as $pair) { list($key, $value) = explode('=', $pair, 2); $value = urldecode($value); if (in_array($key, $multivalue_keys)) { $params[$key][] = $value; } elseif ($key == 'q') { //error_log($value); $keys = $value; } elseif ($key == 'core') { $core = "{$value}/"; } else { $params[$key] = $value; } } try { $response = $solr->search($keys, $params['start'], $params['rows'], $params); //var_dump($response); $numfound = $response->response->numFound; foreach ($response->response->docs as $doc) { foreach ($doc as $field => $value) { if ($field == "medium_image_url") { $picture_url = $value; break; } } } } catch (Exception $e) { die($e->__toString()); } //error_log($response->getRawResponse()); //print $response->getRawResponse(); /*ררררררררר*/ $fq = array(); $q = array(); // proceed only if 'start' param was null ('start' is set when the user uses pagination in website, and we want to avoid duplication on search string) if (!isset($params['start'])) { // process q if ($keys != '') { $q = explode(",", $keys); // remove default 'q' value if (($key = array_search($q_default, $q)) !== false) { unset($q[$key]); } array_filter($q); } // process fq if (isset($params['fq'])) { $fq = $params['fq']; // remove 'tag' facet $matches = array_filter($fq, function ($var) use($fq_tag) { return preg_match("/\\b{$fq_tag}\\b/i", $var); }); foreach ($matches as $key => $value) { unset($fq[$key]); } array_filter($fq); } if (count($q) + count($fq) > 0) { //$solr_search_log = new Apache_Solr_Service('csdev-seb', 8180, '/solr-example/dev_search_log/' . $core); //$document = new Apache_Solr_Document(); $document->id = uniqid(); //or something else suitably unique $document->q = $q; $document->facet = $fq; $document->ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['REMOTE_ADDR'] + "-" + $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; $document->last_update = gmdate('Y-m-d\\TH:i:s\\Z', strtotime("now")); $document->numfound = $numfound; // user called for detailed view of an artwork? $artwork = "id_s"; $matches = array_filter($q, function ($var) use($artwork) { return preg_match("/\\b{$artwork}\\b/i", $var); }); if (count($matches) > 0) { if (count($q_prev) > 0) { $document->prev_q = $q_prev; } if (count($fq_prev) > 0) { $document->prev_facet = $fq_prev; } if ($picture_url != '') { $document->picture_url = $picture_url; } } $solr_search_log->addDocument($document); //if you're going to be adding documents in bulk using addDocuments with an array of documents is faster //$solr_search_log->deleteByQuery('*:*'); $solr_search_log->commit(); //echo 'ok'; } } /*ררררררררררר*/ echo $_GET['callback'] . '(' . $response->getRawResponse() . ')'; } } }
public function getProductByCategoryID($category_id, $offset = 0, $limit = 1, $orderBY = null, $orderWay = 'ASC', $company_id = null, $useSolr = false) { $this->db->cache_delete('product', 'ajax_list'); if ($useSolr) { $this->load->library("solr/Solr"); $solrServer = $this->config->config['solr_server_address']; $solrServerPort = $this->config->config['solr_port']; $solrPath = $this->config->config['solr_path']; $collection = 'products'; $solr = new Apache_Solr_Service($solrServer, $solrServerPort, $solrPath . $collection); try { $query = $category_id == 1 ? "*:*" : "category_id:" . $category_id; // urlencode(" *:*&sort=price+ASC "); $searchOptions = array('sort' => 'product desc'); $results = $solr->search($query, $offset, $limit, $searchOptions); if ($results) { $total = (int) $results->response->numFound; $start = min(1, $total); $end = min($limit, $total); } foreach ($results->response->docs as $p) { if (!isset($p->id_image)) { $p->id_image = $this->get_image(intval($p->product_id)); } } $result = array('products' => $results->response->docs, 'total' => $total, 'start' => $start, 'end' => $end); return $result; } catch (Exception $e) { print_r($e); } return; } else { if ($orderBY == 'product_id') { $orderBY = 'p1.product_id'; } $query = 'SELECT * FROM (SELECT product_id as pid FROM (select id_category as category_id from ' . $this->db->dbprefix . 'categoryindex where id_parent=' . $this->db->escape($category_id != 1 ? $category_id : 1) . ') pci left join ' . $this->db->dbprefix . 'products_categories pc on pc.category_id = pci.category_id' . ' LIMIT ' . $this->db->escape(intval($offset)) . ',' . $this->db->escape(intval($limit)) . ') p LEFT JOIN ' . $this->db->dbprefix . 'products p1 ON p.pid=p1.product_id LEFT JOIN ' . $this->db->dbprefix . 'product_descriptions pd ON p.pid=pd.product_id LEFT JOIN ' . $this->db->dbprefix . 'product_prices pp ON p.pid=pp.product_id LEFT JOIN ' . $this->db->dbprefix . 'image pi ON p.pid=pi.product_id '; if ($company_id) { $query .= 'WHERE p1.company_id=' . $this->db->escape($company_id); } $query .= ' GROUP BY p.pid'; if ($orderBY) { $query .= ' order by ' . $this->db->escape_str($orderBY) . ' ' . $orderWay; } //// $query.=' LIMIT ' . $this->db->escape(intval($limit)). ',' . $this->db->escape(intval($offset)); // print_r($query); // die; $result = $this->db->query($query); $this->load->driver('cache'); $totals = array(); if ($this->cache->apc) { $totals = $this->cache->apc->get('totals'); } $totalProduct = 0; if (isset($totals[$category_id])) { $totalProduct = $totals[$category_id]; } else { $queryTotal = '(SELECT product_id as pid FROM (select id_category as category_id from ' . $this->db->dbprefix . 'ps_categoryindex where id_parent=' . $this->db->escape($category_id != 1 ? $category_id : 1) . ') pci left join ' . $this->db->dbprefix . 'products_categories pc on pc.category_id = pci.category_id' . ')'; $rs = $this->db->query($queryTotal); $totalProduct = $rs->num_rows(); if ($this->cache->apc) { $totals = $this->cache->apc->get('totals'); if (is_array($totals)) { $totals[$category_id] = $totalProduct; } else { $totals = array($category_id => $totalProduct); } $this->cache->apc->save('totals', $totals, 1000); } } $start = min(1, $totalProduct); $end = min($limit, $totalProduct); $results = array('products' => $result->result_object(), 'total' => $totalProduct, 'start' => $start, 'end' => $end); } return $results; }
case 'norcommmouse': $reportname='Available mice produced by NorCOMM'; $reporttype='mouse'; $reporttypedisplay='Mice'; $reportprogram='norcomm'; $query = 'available_product:"NorCOMM mouse available"'; break; default: $reportname='Report not found'; $reportprogram='notfound'; $reporttypedisplay='Vectors, ES cells, mice'; $query = 'available_product:nothing'; break; } $response = $solr->search( $query, $offset, $limit, array('sort' => 'symbol asc')); // ------------------------------------ // Uncomment to sort by relevancy score // $response = $solr->search( $query, $offset, $limit, array( 'fl'=>'*,score', 'indent'=>'on', 'debugQuery'=>'on')); // ------------------------------------ } else { // nothing was searched for.... just return all available products $query="available_product:[* TO *]"; $reportname='All available products'; $response = $solr->search( $query, $offset, $limit, array('sort' => 'symbol asc')); } ?> <? if ($reportprogram=='notfound') : ?> <h1 style="text-align:center;"><?php
$offset = $_GET['page'] * $limit - $limit; } //Query the service with the values and print the results in a table $responses = array(); if($_GET['list']) { // default query is all genes on all lists $query = "KOMP_list:Visible OR KOMP_list:Master OR KOMP_list:Target OR KOMP_list:High Prority"; if ($_GET['list'] == "Target") { // all genes on the target list $query = "KOMP_list:Target OR KOMP_list:High Prority"; } else if ($_GET['list'] == "Master") { // all genes on the master list $query = "KOMP_list:Master OR KOMP_list:Target OR KOMP_list:High Prority"; } $response = $solr->search($query, $offset, $limit, array('sort' => 'symbol asc', 'hl'=>'true', 'hl.fl=symbol,synonym')); } else if($_GET['chromosome']) { // seaching for all genes on a chromosome $query = "chromosome: ". $_GET['chromosome']; $response = $solr->search($query, $offset, $limit, array('sort' => 'start asc')); } else if($_GET['symbol']) { // searching by the first letter of the symbol $symbol = strtolower($_GET['symbol']); $symbol .= (strstr($symbol, "*")) ? "" : "*"; $query = "symbol: $symbol"; if ($_GET['symbol'] == '0-9') { $query = "symbol: (0* OR 1* OR 2* OR 3* OR 4* OR 5* OR 6* OR 7* OR 8* OR 9*)"; } $response = $solr->search($query, $offset, $limit, array('sort' => 'symbol asc')); } else if($_GET['criteria']) { // Normal search string
</ul> </div> <!-- /#nav --> <div id="container"> <div id="center"> <div> <div width="100%" style="margin-top:5px;text-align: left;" align="left"> <? require_once('Apache/Solr/Service.php'); // Instance a new solr object $solr = new Apache_Solr_Service( 'prototype.knockoutmouse.org', '80', '/' ); // Query the solr service if ($_GET['mgiid']) { $response = $solr->search( "mgiid:".str_replace(":", "\:", $_GET['mgiid']), $offset, $limit, array('sort' => 'symbol asc')); } else { print "Missing MGI ID"; } // sequence sorting function so ($a, $b) { // Sort by product score first // 0 = no product // 1 = vectors available // 2 = es cells available // 3 = mice available if ($a['score']<$b['score']) { return 1; } else if ($a['score']>$b['score']) {
/** * Performs a search. * * @param string $query query string / search term * @param integer $offset result offset for pagination * @param integer $limit number of results to retrieve * @param array $params additional HTTP GET parameters * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST) * @return Apache_Solr_Response Solr response * @throws RuntimeException if Solr returns a HTTP status code other than 200 */ public function search($query, $offset = 0, $limit = 10, $params = array(), $method = self::METHOD_GET) { $response = parent::search($query, $offset, $limit, $params, $method); $this->hasSearched = TRUE; $this->responseCache = $response; if ($response->getHttpStatus() != 200) { throw new RuntimeException('Invalid query. Solr returned an error: ' . $response->getHttpStatus() . ' ' . $response->getHttpStatusMessage(), 1293109870); } return $response; }
function get_search($arr = array(), $startindex = 0, $pagesize = 20) { if (!class_exists('Apache_Solr_Service', false)) { require TIPASK_ROOT . '/api/SolrPhpClient/Apache/Solr/Service.php'; } $solr = new Apache_Solr_Service($this->onlineConfig['SOLR_SEARCH_SERVER'], $this->onlineConfig['SOLR_PORT'], '/solr'); //SOLR_SEARCH_SERVER foreach ($arr as $key => $val) { $response = $solr->search($key . ':' . $val, $startindex, $pagesize, array('sort' => 'boost desc,time desc,score desc')); } return json_decode($response->getRawResponse(), true); }
/** * Performs a search. * * @param string query string / search term * @param integer result offset for pagination * @param integer number of results to retrieve * @param array additional HTTP GET parameters * @return Apache_Solr_Response Solr response */ public function search($query, $offset = 0, $limit = 10, $params = array()) { $response = parent::search($query, $offset, $limit, $params); $this->hasSearched = TRUE; if (!is_object($response)) { throw new RuntimeException('Solr server not responding.', 1293109870); } $this->responseCache = $response; return $response; }
/** * Realiza un query en Solr, aplicando la configuración estándar especificada * en Joomla y los parámetros adicionales indicados. * * @param int $limit * @param int $limitstart * @param string $queryParams * @return Array */ function getSolrResults($limitstart = 0, $limit = 0, $additionalParams = array()) { $eqZonalesParams =& JComponentHelper::getParams('com_eqzonales'); // recupera parametros $solr_url = $eqZonalesParams->get('solr_url', null); $solr_port = $eqZonalesParams->get('solr_port', null); $solr_webapp = $eqZonalesParams->get('solr_webapp', null); $solr_querytype = $eqZonalesParams->get('solr_querytype', null); // No se especifico la url de solr if ($solr_url == null) { return null; } // No se especifico el puerto de solr if ($solr_port == null) { return null; } // No se especifico el puerto de webapp if ($solr_webapp == null) { return null; } // No se especifico un QueryType apropiado if ($solr_querytype == null) { return null; } // The Apache Solr Client library should be on the include path // which is usually most easily accomplished by placing in the // same directory as this script ( . or current directory is a default // php include path entry in the php.ini) jimport('SolrPhpClient.Apache.Solr.Service'); // create a new solr service instance - host, port, and webapp // path (all defaults in this example) $solr = new Apache_Solr_Service($solr_url, $solr_port, $solr_webapp); $queryParams = array(); $fqParams = array(); $stateFrom = JRequest::getVar('stateFrom') != null ? JRequest::getInt('stateFrom') : 1; $stateTo = JRequest::getVar('stateTo') != null ? JRequest::getInt('stateTo') : 1; $fqParams[] = $this->getWhere($stateFrom, $stateTo); foreach ($additionalParams as $param) { $fqParams[] = $param; } $disabledBands = $this->getDisabledBands(); if (strlen($disabledBands) > 0) { $fqParams[] = $disabledBands; } $queryParams['fq'] = $fqParams; $queryParams['sort'] = $this->getOrder(); $queryParams['fl'] = $this->getFieldList(); $queryParams['bq'] = $this->getEqPreferences(); $queryParams['qt'] = $solr_querytype; $queryParams['bf'] = 'recip(map(rord(modified),10,100,99000),100,95000,95000)^350'; try { $results = $solr->search("", $limitstart, $limit, $queryParams); foreach ($results->response->docs as $doc) { $doc->slug = strlen($doc->alias) ? "{$doc->id}:{$doc->alias}" : $doc->id; $doc->catslug = $doc->catid; } } catch (Exception $e) { return null; } return $results; }
/** * Processes a search request. * * @access public * * @param string $query: The search query * * @return tx_dlf_list The result list */ public function search($query = '') { // Perform search. $results = $this->service->search((string) $query, 0, $this->limit, $this->params); $this->numberOfHits = count($results->response->docs); $toplevel = array(); $checks = array(); // Get metadata configuration. if ($this->numberOfHits > 0) { $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_metadata.index_name AS index_name', 'tx_dlf_metadata', 'tx_dlf_metadata.is_sortable=1 AND tx_dlf_metadata.pid=' . intval($this->cPid) . tx_dlf_helper::whereClause('tx_dlf_metadata'), '', '', ''); $sorting = array(); while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { $sorting[$resArray['index_name']] = $resArray['index_name'] . '_sorting'; } } // Keep track of relevance. $i = 0; // Process results. foreach ($results->response->docs as $doc) { // Split toplevel documents from subparts. if ($doc->toplevel == 1) { // Prepare document's metadata for sorting. $docSorting = array(); foreach ($sorting as $index_name => $solr_name) { if (!empty($doc->{$solr_name})) { $docSorting[$index_name] = is_array($doc->{$solr_name}) ? $doc->{$solr_name}[0] : $doc->{$solr_name}; } } // Preserve relevance ranking. if (!empty($toplevel[$doc->uid]['s']['relevance'])) { $docSorting['relevance'] = $toplevel[$doc->uid]['s']['relevance']; } $toplevel[$doc->uid] = array('u' => $doc->uid, 's' => $docSorting, 'p' => !empty($toplevel[$doc->uid]['p']) ? $toplevel[$doc->uid]['p'] : array()); } else { $toplevel[$doc->uid]['p'][] = $doc->id; if (!in_array($doc->uid, $checks)) { $checks[] = $doc->uid; } } // Add relevance to sorting values. if (empty($toplevel[$doc->uid]['s']['relevance'])) { $toplevel[$doc->uid]['s']['relevance'] = str_pad($i, 6, '0', STR_PAD_LEFT); } $i++; } // Check if the toplevel documents have metadata. foreach ($checks as $check) { if (empty($toplevel[$check]['u'])) { // Get information for toplevel document. $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dlf_documents.uid AS uid,tx_dlf_documents.metadata_sorting AS metadata_sorting', 'tx_dlf_documents', 'tx_dlf_documents.uid=' . intval($check) . tx_dlf_helper::whereClause('tx_dlf_documents'), '', '', '1'); // Process results. if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); // Prepare document's metadata for sorting. $sorting = unserialize($resArray['metadata_sorting']); if (!empty($sorting['type']) && tx_dlf_helper::testInt($sorting['type'])) { $sorting['type'] = tx_dlf_helper::getIndexName($sorting['type'], 'tx_dlf_structures', $this->cPid); } if (!empty($sorting['owner']) && tx_dlf_helper::testInt($sorting['owner'])) { $sorting['owner'] = tx_dlf_helper::getIndexName($sorting['owner'], 'tx_dlf_libraries', $this->cPid); } if (!empty($sorting['collection']) && tx_dlf_helper::testInt($sorting['collection'])) { $sorting['collection'] = tx_dlf_helper::getIndexName($sorting['collection'], 'tx_dlf_collections', $this->cPid); } // Preserve relevance ranking. if (!empty($toplevel[$check]['s']['relevance'])) { $sorting['relevance'] = $toplevel[$check]['s']['relevance']; } $toplevel[$check] = array('u' => $resArray['uid'], 's' => $sorting, 'p' => $toplevel[$check]['p']); } else { // Clear entry if there is no (accessible) toplevel document. unset($toplevel[$check]); } } } // Save list of documents. $list = t3lib_div::makeInstance('tx_dlf_list'); $list->reset(); $list->add(array_values($toplevel)); // Set metadata for search. $list->metadata = array('label' => '', 'description' => '', 'options' => array('source' => 'search', 'select' => $query, 'userid' => 0, 'params' => $this->params, 'core' => $this->core, 'pid' => $this->cPid, 'order' => 'relevance', 'order.asc' => TRUE)); return $list; }
/** * * @param <type> $limit * @param <type> $limitstart * @param <type> $queryParams * @return <type> */ function getSolrResults($text = '', $limitstart = 0, $limit = 0, $additionalParams = '') { $zonalesParams =& JComponentHelper::getParams('com_eqzonales'); // recupera parametros $solr_url = $zonalesParams->get('solr_url', null); $solr_port = $zonalesParams->get('solr_port', null); $solr_webapp = $zonalesParams->get('solr_webapp', null); // No se especifico la url de solr if ($solr_url == null) { return null; } // No se especifico el puerto de solr if ($solr_port == null) { return null; } // No se especifico el puerto de webapp if ($solr_webapp == null) { return null; } // The Apache Solr Client library should be on the include path // which is usuaPlly most easily accomplished by placing in the // same directory as this script ( . or current directory is a default // php include path entry in the php.ini) jimport('SolrPhpClient.Apache.Solr.Service'); // create a new solr service instance - host, port, and webapp // path (all defaults in this example) $solr = new Apache_Solr_Service($solr_url, $solr_port, $solr_webapp); $queryParams = array(); $fqParams = array(); $fqParams[] = $this->getWhere(); if (strlen($additionalParams) > 0) { $fqParams[] = $additionalParams; } $queryParams['fq'] = $fqParams; $queryParams['sort'] = $this->getOrder(); $queryParams['fl'] = $this->getFieldList(); $queryParams['bq'] = $this->getEqPreferences(); $queryParams['qt'] = "zonalesContent"; try { $results = $solr->search($text, $limitstart, $limit, $queryParams); } catch (Exception $e) { return null; } return $results; }