Esempio n. 1
0
 /**
  *
  * 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;
     }
 }
Esempio n. 2
0
 function emptyAction()
 {
     //$log = new Kutu_Log();
     //$registry = Zend_Registry::getInstance();
     //$conf = $registry->get('config');
     $solr = new Apache_Solr_Service('localhost', '8983', '/solr/core0');
     $solr->deleteByQuery('*:*');
     $solr->commit();
     //$log->info("Indexing empty successfully");
     $this->view->success = true;
 }
Esempio n. 3
0
 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;
     }
 }
Esempio n. 4
0
 /**
  *
  * @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();
 }
Esempio n. 5
0
 /**
  * Constructor, retrieve config for connection to solr server.
  */
 public function __construct()
 {
     $_host = Mage::getStoreConfig('solr/server/host');
     $_port = Mage::getStoreConfig('solr/server/port');
     $_path = Mage::getStoreConfig('solr/server/path');
     parent::__construct($_host, $_port, $_path);
 }
Esempio n. 6
0
 public function getSolr()
 {
     require_once __DIR__ . '/../' . 'Lib/Apache/Solr/Apache_Solr_Service.php';
     $em = $this->em;
     $solrservers = $em->getRepository('EcoInformaticaAnalizadorBundle:SolrServer')->findAll();
     if (count($solrservers) > 0) {
         foreach ($solrservers as $solrserver) {
             $USR = $solrserver->getUsername();
             $PSWD = $solrserver->getPassword();
             $HOST = $solrserver->getHost();
             $PORT = $solrserver->getPort();
             $SOLRPATH = $solrserver->getPath();
             $solr = new \Apache_Solr_Service("{$USR}:{$PSWD}@{$HOST}", $PORT, $SOLRPATH);
             if ($solr->ping()) {
                 break;
             }
         }
     } else {
         $solr = false;
     }
     return $solr;
 }
 /**
  * Construct service
  */
 public function __construct()
 {
     $storeId = Mage::app()->getStore()->getId();
     if (Mage::getStoreConfig('catalog/search/engine', $storeId) == 'enterprise_search/engine') {
         $host = Mage::getStoreConfig('catalog/search/solr_server_hostname', $storeId);
         $port = Mage::getStoreConfig('catalog/search/solr_server_port', $storeId);
         $path = Mage::getStoreConfig('catalog/search/solr_server_path', $storeId);
     } else {
         $host = Mage::getStoreConfig('catalog/autocompleterecommendations/solr_server_hostname', $storeId);
         $port = Mage::getStoreConfig('catalog/autocompleterecommendations/solr_server_port', $storeId);
         $path = Mage::getStoreConfig('catalog/autocompleterecommendations/solr_server_path', $storeId);
         if (!$host || !$port || !$path) {
             $message = Mage::helper('autocompleterecommendations')->__('Solr engine parameters, host, port and path are required.');
             Mage::log($message, null, 'extensions_store_autocompleterecommendations.log');
             Mage::throwException($message);
             die;
         }
     }
     parent::__construct($host, $port, $path);
 }
Esempio n. 8
0
function db_store_article($article, $PageID = 0, $updating = false)
{
    global $db;
    global $config;
    $update = false;
    $id = 0;
    // If we are editing an existing reference then we already know its id
    if (isset($article->reference_id)) {
        $id = $article->reference_id;
    } else {
        $id = db_find_article($article);
    }
    if ($id != 0) {
        if ($updating) {
            $update = true;
        } else {
            return $id;
        }
    }
    // Try and trap empty references
    if ($id == 0) {
        $ok = false;
        if (isset($article->title)) {
            $ok = $article->title != '';
        }
        if (!$ok) {
            return 0;
        }
    }
    if (!isset($article->genre)) {
        $article->genre = 'article';
    }
    $keys = array();
    $values = array();
    // Article metadata
    foreach ($article as $k => $v) {
        switch ($k) {
            // Ignore as it's an array
            case 'authors':
                break;
            case 'date':
                $keys[] = 'date';
                $values[] = $db->qstr($v);
                if (!isset($article->year)) {
                    $keys[] = 'year';
                    $values[] = $db->qstr(year_from_date($v));
                }
                break;
                // Don't store BHL URL here
            // Don't store BHL URL here
            case 'url':
                if (preg_match('/^http:\\/\\/(www\\.)?biodiversitylibrary.org\\/page\\/(?<pageid>[0-9]+)/', $v)) {
                } else {
                    // extract Handle if it exists
                    if (preg_match('/^http:\\/\\/hdl.handle.net\\/(?<hdl>.*)$/', $v, $m)) {
                        $keys[] = 'hdl';
                        $values[] = $db->qstr($m['hdl']);
                    } else {
                        $keys[] = $k;
                        $values[] = $db->qstr($v);
                    }
                }
                break;
                // Things we store as is
            // Things we store as is
            case 'title':
            case 'secondary_title':
            case 'volume':
            case 'series':
            case 'issue':
            case 'spage':
            case 'epage':
            case 'year':
            case 'date':
            case 'issn':
            case 'genre':
            case 'doi':
            case 'hdl':
            case 'lsid':
            case 'oclc':
            case 'pdf':
            case 'abstract':
            case 'pmid':
                $keys[] = $k;
                $values[] = $db->qstr($v);
                break;
                // Things we ignore
            // Things we ignore
            default:
                break;
        }
    }
    // Date
    if (!isset($article->date) && isset($article->year)) {
        $keys[] = 'date';
        $values[] = $db->qstr($article->year . '-00-00');
    }
    // BHL PageID
    if ($PageID != 0) {
        $keys[] = 'PageID';
        $values[] = $PageID;
    }
    // SICI
    $s = new Sici();
    $sici = $s->create($article);
    if ($sici != '') {
        $keys[] = 'sici';
        $values[] = $db->qstr($sici);
    }
    if ($update) {
        // Versioning?
        // Delete links	(author, pages, etc)
        // Don't delete page range as we may loose plates, etc. outside range
        /*
        $sql = 'DELETE FROM rdmp_reference_page_joiner WHERE reference_id=' . $id;
        $result = $db->Execute($sql);
        if ($result == false) die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        */
        $sql = 'DELETE FROM rdmp_author_reference_joiner WHERE reference_id = ' . $id;
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
        // update (updated timestamp will be automatically updated)
        $sql = 'UPDATE rdmp_reference SET ';
        $num_values = count($keys);
        for ($i = 0; $i < $num_values; $i++) {
            if ($i > 0) {
                $sql .= ', ';
            }
            $sql .= $keys[$i] . '=' . $values[$i];
        }
        $sql .= ' WHERE reference_id=' . $id;
        /*		$cache_file = @fopen('/tmp/update.sql', "w+") or die("could't open file");
        		@fwrite($cache_file, $sql);
        		fclose($cache_file);
        */
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
    } else {
        // Adding article for first time so add 'created' and 'updated' timestamp
        $keys[] = 'created';
        $values[] = 'NOW()';
        $keys[] = 'updated';
        $values[] = 'NOW()';
        $sql = 'INSERT INTO rdmp_reference (' . implode(",", $keys) . ') VALUES (' . implode(",", $values) . ')';
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
        $id = $db->Insert_ID();
        // Store reference_cluster_id which we can use to group duplicates, by default
        // reference_cluster_id = reference_id
        $sql = 'UPDATE rdmp_reference SET reference_cluster_id=' . $id . ' WHERE reference_id=' . $id;
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
    }
    // Indexing-------------------------------------------------------------------------------------
    if (1) {
        // solr
        // this code is redundant with code in reference.php but I use different objects
        // here and there (doh!). Also once we've added old stuff to solr this is the only place we
        // should be calling solr
        $solr = new Apache_Solr_Service('localhost', '8983', '/solr');
        if (!$solr->ping()) {
            echo 'Solr service not responding.';
            exit;
        }
        $item = array();
        $item['id'] = 'reference/' . $id;
        $item['title'] = $article->title;
        $item['publication_outlet'] = $article->secondary_title;
        $item['year'] = $article->year;
        $authors = array();
        foreach ($article->authors as $a) {
            $authors[] = $a->forename . ' ' . $a->surname;
        }
        $item['authors'] = $authors;
        $citation = '';
        $citation .= ' ' . $article->year;
        $citation .= ' ' . $article->title;
        $citation .= ' ' . $article->secondary_title;
        $citation .= ' ' . $article->volume;
        if (isset($article->issue)) {
            $citation .= '(' . $article->issue . ')';
        }
        $citation .= ':';
        $citation .= ' ';
        $citation .= $article->spage;
        if (isset($article->epage)) {
            $citation .= '-' . $article->epage;
        }
        $item['citation'] = $citation;
        $text = '';
        $num_authors = count($article->authors);
        $count = 0;
        if ($num_authors > 0) {
            foreach ($article->authors as $author) {
                $text .= $author->forename . ' ' . $author->lastname;
                if (isset($author->suffix)) {
                    $text .= ' ' . $author->suffix;
                }
                $count++;
                if ($count == 2 && $num_authors > 3) {
                    $text .= ' et al.';
                    break;
                }
                if ($count < $num_authors - 1) {
                    $text .= ', ';
                } else {
                    if ($count < $num_authors) {
                        $text .= ' and ';
                    }
                }
            }
        }
        $item['citation'] = $text . ' ' . $citation;
        $parts = array();
        $parts[] = $item;
        //print_r($parts);
        // add to solr
        $documents = array();
        foreach ($parts as $item => $fields) {
            $part = new Apache_Solr_Document();
            foreach ($fields as $key => $value) {
                if (is_array($value)) {
                    foreach ($value as $datum) {
                        $part->setMultiValue($key, $datum);
                    }
                } else {
                    $part->{$key} = $value;
                }
            }
            $documents[] = $part;
        }
        //
        //
        // Load the documents into the index
        //
        try {
            $solr->addDocuments($documents);
            $solr->commit();
            $solr->optimize();
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    } else {
        $sql = 'DELETE FROM rdmp_text_index WHERE (object_uri=' . $db->qstr($config['web_root'] . 'reference/' . $id) . ')';
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
        // Only do this if we have a title, as sometimes we don't (e.g. CrossRef lacks metadata)
        if (isset($article->title)) {
            $sql = 'INSERT INTO rdmp_text_index(object_type, object_id, object_uri, object_text)
			VALUES ("title"' . ', ' . $id . ', ' . $db->qstr($config['web_root'] . 'reference/' . $id) . ', ' . $db->qstr($article->title) . ')';
            $result = $db->Execute($sql);
            if ($result == false) {
                die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
            }
        }
    }
    // Versioning-----------------------------------------------------------------------------------
    // Store this object in version table so we can recover it if we overwrite item
    $ip = getip();
    $sql = 'INSERT INTO rdmp_reference_version(reference_id, ip, json) VALUES(' . $id . ', ' . 'INET_ATON(\'' . $ip . '\')' . ',' . $db->qstr(json_encode($article)) . ')';
    $result = $db->Execute($sql);
    if ($result == false) {
        die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
    }
    // Author(s)------------------------------------------------------------------------------------
    // Store author as and link to the article
    if (isset($article->authors)) {
        db_store_authors($id, $article->authors);
    }
    // Store page range (only if not updating, otherwise we may loose plates, etc.
    // that aren't in page range)
    if ($PageID != 0 && !$update) {
        $page_range = array();
        if (isset($article->spage) && isset($article->epage)) {
            $page_range = bhl_page_range($PageID, $article->epage - $article->spage + 1);
        } else {
            // No epage, so just get spage (to do: how do we tell user we don't have page range?)
            $page_range = bhl_page_range($PageID, 0);
        }
        //print_r($page_range);
        $count = 0;
        foreach ($page_range as $page) {
            $sql = 'INSERT INTO rdmp_reference_page_joiner (reference_id, PageID, page_order) 
			VALUES (' . $id . ',' . $page . ',' . $count++ . ')';
            $result = $db->Execute($sql);
            if ($result == false) {
                die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
            }
        }
    }
    // Tweet----------------------------------------------------------------------------------------
    if (!$update) {
        if ($config['twitter']) {
            $url = $config['web_root'] . 'reference/' . $id . ' ' . '#bhlib';
            // url + hashtag
            $url_len = strlen($url);
            $status = '';
            if (isset($article->title)) {
                $status = $article->title;
                $status_len = strlen($status);
                $extra = 140 - $status_len - $url_len - 1;
                if ($extra < 0) {
                    $status_len += $extra;
                    $status_len -= 1;
                    $status = substr($status, 0, $status_len);
                    $status .= '…';
                }
            }
            $status .= ' ' . $url;
            tweet($status);
        }
    }
    return $id;
}
Esempio n. 9
0
 /**
  * 
  * @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);
 }
Esempio n. 10
0
 /**
  * Escape a value meant to be contained in a phrase for special query
  * characters
  *
  * @param string $value            
  * @return string
  */
 public static function escapePhrase($value)
 {
     return parent::escapePhrase($value);
 }
Esempio n. 11
0
 public function isActive()
 {
     require_once __DIR__ . '/../' . 'Lib/Apache/Solr/Apache_Solr_Service.php';
     $solr = new \Apache_Solr_Service("{$this->username}:{$this->password}@{$this->host}", $this->port, $this->path);
     if ($solr->ping()) {
         return true;
     } else {
         return false;
     }
 }
Esempio n. 12
0
 /**
  * initializes various URLs, including the Luke URL
  *
  * @return void
  */
 protected function _initUrls()
 {
     parent::_initUrls();
     $this->_lukeUrl = $this->_constructUrl(self::LUKE_SERVLET, array('numTerms' => '0', 'wt' => self::SOLR_WRITER));
     $this->_pluginsUrl = $this->_constructUrl(self::PLUGINS_SERVLET, array('wt' => self::SOLR_WRITER));
     $pathElements = explode('/', trim($this->_path, '/'));
     $this->_coresUrl = $this->_scheme . '://' . $this->_host . ':' . $this->_port . '/' . $pathElements[0] . '/' . self::CORES_SERVLET;
     $this->_schemaUrl = $this->_constructUrl(self::SCHEMA_SERVLET);
     $managedLanguage = $this->getManagedLanguage();
     $this->_synonymsUrl = $this->_constructUrl(self::SYNONYMS_SERVLET) . $managedLanguage;
     $this->_stopWordsUrl = $this->_constructUrl(self::STOPWORDS_SERVLET) . $managedLanguage;
 }
Esempio n. 13
0
 /**
  * Add search query filter
  *
  * @param   Mage_CatalogSearch_Model_Query $query
  * @return  Mage_CatalogSearch_Model_Mysql4_Search_Collection
  */
 public function addSearchFilter($query = NULL)
 {
     if (is_null($query)) {
         $query = Mage::helper('solr')->getQuery();
     }
     $where = '';
     $query = Apache_Solr_Service::escape($query);
     //$query = $this->addFuzzySearch($query);
     $where = 'attr_t_search_content_heading:' . $query . '*';
     $where .= ' OR attr_t_search_content:' . $query . '*';
     $where .= ' OR attr_t_search_title:' . $query . '*';
     $this->getSelect()->where($where);
     return $this;
 }
Esempio n. 14
0
 * @version     $Id$
 */
function printMessage($message)
{
    echo strftime('%d.%m.%Y %H:%M:%S', time()) . $message . "\n";
}
define('APPLICATION_ENV', 'production');
// basic bootstrapping
require_once dirname(__FILE__) . '/../common/bootstrap.php';
$config = Zend_Registry::get('Zend_Config');
$host = $config->searchengine->solr->host;
$port = $config->searchengine->solr->port;
$baseUri = $config->searchengine->solr->path;
$EOL = "\n";
$commitRange = 100;
$solr = new Apache_Solr_Service($host, $port, $baseUri);
if (false === $solr->ping()) {
    echo 'Could not connect to solr service.' . $EOL;
    return;
}
$startTime = time();
$docIds = Opus_Document::getAllIds();
$documents = array();
$conf = Zend_Registry::get('Zend_Config');
$baseFilePath = null;
if (true === isset($conf->file->destinationPath) and true === is_dir($conf->file->destinationPath)) {
    $baseFilePath = $conf->file->destinationPath;
}
foreach ($docIds as $docId) {
    printMessage(' Indexing document : ' . $docId);
    $opusDoc = new Opus_Document($docId);
Esempio n. 15
0
 /**
  * Iterate through available read services and select the first with a ping
  * that satisfies configured timeout restrictions (or the default)
  *
  * @return Apache_Solr_Service
  *
  * @throws Apache_Solr_NoServiceAvailableException If there are no read services that meet requirements
  */
 protected function _selectReadService($forceSelect = false)
 {
     if (!$this->_currentReadService || !isset($this->_readableServices[$this->_currentReadService]) || $forceSelect) {
         if ($this->_currentReadService && isset($this->_readableServices[$this->_currentReadService]) && $forceSelect) {
             // we probably had a communication error, ping the current read service, remove it if it times out
             if ($this->_readableServices[$this->_currentReadService]->ping($this->_readPingTimeout) === false) {
                 $this->removeReadService($this->_currentReadService);
             }
         }
         if (count($this->_readableServices)) {
             // select one of the read services at random
             $ids = array_keys($this->_readableServices);
             $id = $ids[rand(0, count($ids) - 1)];
             $service = $this->_readableServices[$id];
             if (is_array($service)) {
                 //convert the array definition to a client object
                 $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
                 $this->_readableServices[$id] = $service;
             }
             $service->setCreateDocuments($this->_createDocuments);
             $this->_currentReadService = $id;
         } else {
             throw new Apache_Solr_NoServiceAvailableException('No read services were available');
         }
     }
     return $this->_readableServices[$this->_currentReadService];
 }
Esempio n. 16
0
 public function __construct($host = 'localhost', $port = 8180, $path = '/solr/')
 {
     parent::__construct($host, $port, $path);
     echo '<pre>' . print_r($this->ping(), true) . '</pre>';
     exit;
 }
Esempio n. 17
0
 public function testOptimize()
 {
     // set a mock transport
     $mockTransport = $this->getMockHttpTransportInterface();
     // setup expected call and response
     $mockTransport->expects($this->once())->method('performPostRequest')->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response()));
     $fixture = new Apache_Solr_Service();
     $fixture->setHttpTransport($mockTransport);
     $fixture->optimize();
 }
Esempio n. 18
0
 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;
 }
 /**
  * Central method for making a post operation against this Solr Server
  *
  * @param string $url
  * @param string $rawPost
  * @param float $timeout Read timeout in seconds
  * @param string $contentType
  * @return Apache_Solr_Response
  *
  * @throws Exception If a non 200 response status is returned
  */
 protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
 {
     stream_context_set_option($this->_postContext, 'http', 'header', "Authorization: Basic " . base64_encode($this->getUserLogin() . ':' . $this->getPassword()));
     return parent::_sendRawPost($url, $rawPost, $timeout, $contentType);
 }
Esempio n. 20
0
                    <li class="menu-161"><a href="/faq" title="FAQ">FAQ</a></li>
                    <li class="menu-270"><a href="/content/order-products" title="Order Products">Order Products</a></li>
                    <li class="menu-164 last"><a href="/contact" title="">Contact IKMC</a></li>
                </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' );

$solr = new Apache_Solr_Service( 'prototype.knockoutmouse.org', '80', '/' );

$offset = ($_GET['offset']) ? $_GET['offset'] : 0;
$limit = ($_GET['limit']) ? $_GET['limit'] : 200;

if ($_GET['page']){
    $offset = $_GET['page'] * $limit - $limit;
}

//Query the service with the values and print the results in a table
$responses = array();
if($_GET['report']) {
    // Normal search string
    $report = trim($_GET['report']);
    $reporttype='vector';
    $reporttypedisplay='Vectors';
Esempio n. 21
0
 function delete_search($id)
 {
     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");
     if (is_array($CommonConfig['SOLR_DOMAIN'])) {
         foreach ($CommonConfig['SOLR_DOMAIN'] as $solrDomain) {
             $solr = new Apache_Solr_Service($solrDomain, $CommonConfig['SOLR_PORT'], '/solr');
             $solr->deleteByQuery('id:' . $id);
             file_get_contents('http://' . $solrDomain . ':' . $CommonConfig['SOLR_PORT'] . '/solr/update/json?commit=true');
         }
     } else {
         $solr = new Apache_Solr_Service($CommonConfig['SOLR_DOMAIN'], $CommonConfig['SOLR_PORT'], '/solr');
         $solr->deleteByQuery('id:' . $id);
         file_get_contents('http://' . $CommonConfig['SOLR_DOMAIN'] . ':' . $CommonConfig['SOLR_PORT'] . '/solr/update/json?commit=true');
     }
 }
Esempio n. 22
0
 public function addFilter($object, $attribute, $value)
 {
     if (strlen($value) > 0) {
         $typeConverter = new DMC_Solr_Model_SolrServer_Adapter_Product_TypeConverter();
         $code = $attribute->getAttributeCode();
         $items = $typeConverter->getItems();
         $field = $items[$attribute->getFrontend()->getInputType()]['solr_index_prefix'] . $typeConverter::SUBPREFIX_INDEX . $attribute->getAttributeCode();
         if (is_array($value) && (isset($value['from']) || isset($value['to']))) {
             if (isset($value['from']) && !empty($value['from'])) {
                 $from = $value['from'];
             } else {
                 $from = '*';
             }
             if (isset($value['to']) && !empty($value['to'])) {
                 $to = $value['to'];
             } else {
                 $to = '*';
             }
             $select->where($field . ':[' . $from . ' TO ' . $to . ']');
             return true;
         } else {
             if (is_array($value)) {
                 $value = implode(' ', $value);
             } else {
                 $value = Apache_Solr_Service::escape($value);
                 $value = $this->addFuzzySearch($value);
             }
         }
         $object->getProductCollection()->getSelect()->where($field . ':' . $value);
         return true;
     }
     return false;
 }
 /**
  * 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;
 }
Esempio n. 24
0
 /**
  * Iterate through available write services and select the first with a ping
  * that satisfies configured timeout restrictions (or the default)
  *
  * @return Apache_Solr_Service
  *
  * @throws Exception If there are no write services that meet requirements
  */
 private function _selectWriteService()
 {
     if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService])) {
         foreach ($this->_writeableServices as $id => $service) {
             if (is_array($service)) {
                 //convert the array definition to a client object
                 $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
                 $this->_writeableServices[$id] = $service;
             }
             //check the service
             if ($service->ping($this->_writePingTimeout) !== false) {
                 $this->_currentWriteService = $id;
                 return $this->_writeableServices[$this->_currentWriteService];
             }
         }
         throw new Exception('No write services were available');
     }
     return $this->_writeableServices[$this->_currentWriteService];
 }
Esempio n. 25
0
 public function addDocuments($documents = null, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
 {
     if (count($this->_products)) {
         // sent the xml query to solr
         parent::addDocuments($this->_products);
         Mage::helper('solr/log')->addDebugMessage('Sent ' . count($this->_products) . ' items to the solr server');
         $this->clearDocuments();
     }
 }
 * (at your option) any later version.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * @category    Application
 * @author      Henning Gerhardt <*****@*****.**>
 * @copyright   Copyright (c) 2010
 *              Saechsische Landesbibliothek - Staats- und Universitaetsbibliothek Dresden (SLUB)
 * @license     http://www.gnu.org/licenses/gpl.html General Public License
 * @version     $Id$
 */
define('APPLICATION_ENV', 'production');
// basic bootstrapping
require_once dirname(__FILE__) . '/../common/bootstrap.php';
$config = Zend_Registry::get('Zend_Config');
$host = $config->searchengine->solr->host;
$port = $config->searchengine->solr->port;
$baseUri = $config->searchengine->solr->path;
$EOL = "\n";
$solr = new Apache_Solr_Service($host, $port, $baseUri);
if (false === $solr->ping()) {
    echo 'Could not connect to solr service.' . $EOL;
    return;
}
$solr->deleteByQuery('*:*');
$solr->commit();
$solr->optimize();
echo 'Cleaning solr index on "' . $host . ':' . $port . $baseUri . '" done.' . $EOL;
 /**
  * Put Luke meta-data from the cache into $this->luke when we instantiate.
  *
  * @see Apache_Solr_Service::__construct()
  */
 public function __construct($host = 'localhost', $port = 8180, $path = '/solr/')
 {
     parent::__construct($host, $port, $path);
     $this->luke_cid = "apachesolr:luke:" . md5($this->_lukeUrl);
     $cache = cache_get($this->luke_cid);
     if (isset($cache->data)) {
         $this->luke = $cache->data;
     }
 }
Esempio n. 28
0
/**
 * 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() . ')';
        }
    }
}
 /**
  * This is a singleton class, thus the constructor should be private/protected
  *
  * @access	protected
  *
  * @param	string		$core: The name of the core to use
  *
  * @return	void
  */
 protected function __construct($core)
 {
     // Load class.
     if (!class_exists('Apache_Solr_Service')) {
         require_once t3lib_div::getFileAbsFileName('EXT:' . self::$extKey . '/lib/SolrPhpClient/Apache/Solr/Service.php');
     }
     // Get Solr credentials.
     $conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::$extKey]);
     $host = $conf['solrHost'] ? $conf['solrHost'] : 'localhost';
     // Prepend username and password to hostname.
     if ($conf['solrUser'] && $conf['solrPass']) {
         $host = $conf['solrUser'] . ':' . $conf['solrPass'] . '@' . $host;
     }
     // Set port if not set.
     $port = tx_dlf_helper::intInRange($conf['solrPort'], 1, 65535, 8180);
     // Append core name to path.
     $path = trim($conf['solrPath'], '/') . '/' . $core;
     // Instantiate Apache_Solr_Service class.
     $this->service = t3lib_div::makeInstance('Apache_Solr_Service', $host, $port, $path);
     // Check if connection is established.
     if ($this->service->ping() !== FALSE) {
         // Do not collapse single value arrays.
         $this->service->setCollapseSingleValueArrays = FALSE;
         // Set core name.
         $this->core = $core;
         // Instantiation successful!
         $this->ready = TRUE;
     }
 }
Esempio n. 30
0
 function deleteAction()
 {
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $title = "<h4>HUKUMONLINE INDONESIA: <small>search</small></h4><hr/>";
     echo $title . '<br>';
     $solr = new Apache_Solr_Service('nihki:sirkulasi@202.153.129.35', '8983', '/solr/core-catalog');
     if (!$solr->ping()) {
         echo 'Solr service not responding.';
         exit;
     }
     $a = array('fl17956', 'fl1131');
     foreach ($a as $c) {
         $indexingEngine = Pandamp_Search::manager();
         $indexingEngine->deleteCatalogFromIndex($c);
     }
 }