/**
     * Helper for solr raw searches.
     * Deals with the language, meta_installation, section and visibility filters + solr sharding if any
     * @param array $params
     * @param string $requestType
     * @param bool $useDefaultFilters
     * @return array
     */
    public static function rawSearch( $params, $requestType = 'php', $useDefaultFilters = true, $includeIsInvisible = true )
    {
        eZDebug::accumulatorStart( __CLASS__ . '::' . __FUNCTION__, 'Merck' );

        $findINI = eZINI::instance( 'ezfind.ini' );
        $solrINI = eZINI::instance( 'solr.ini' );
        $siteINI = eZINI::instance();
        $currentLanguage = $siteINI->variable( 'RegionalSettings', 'ContentObjectLocale' );

        // always use extended Dismax query handler when available
        if( isset($params['qt']) && $params['qt'] == 'ezpublish' )
            $params['defType'] = 'edismax';

        if ( $useDefaultFilters )
        {
            if ( !isset( $params['fq'] ) )
                $params['fq'] = '';
            else
                $params['fq'] .= ' AND ';
            $params['fq'] .= implode( ' AND ', array(
                'meta_installation_id_ms:' . eZSolr::installationID(),
                '(attr_offline_date_dt:"1970-01-01T01:00:00Z" OR attr_offline_date_dt:[NOW TO *])',
                '( meta_section_id_si:1 OR meta_section_id_si:3 )',
            ) );
            if ($includeIsInvisible) {
                $params['fq'] .= ' AND ' . 'attr_is_invisible_' . ClusterTool::clusterIdentifier() . '_b:false';
            }
        }

        if ( $findINI->variable( 'LanguageSearch', 'MultiCore' ) == 'enabled' )
        {
            $languageMapping = $findINI->variable( 'LanguageSearch', 'LanguagesCoresMap' );
            $shardMapping = $solrINI->variable( 'SolrBase', 'Shards' );
            $fullSolrURI = $shardMapping[$languageMapping[$currentLanguage]];
        }
        else
        {
            $fullSolrURI = $solrINI->variable( 'SolrBase', 'SearchServerURI' );
            // Autocomplete search should be done in current language and fallback languages
            $validLanguages = array_unique(
                array_merge(
                    LocaleTool::languageList(),
                    array( $currentLanguage )
                )
            );
            if( $useDefaultFilters )
                $params['fq'] .= ' AND meta_language_code_ms:(' . implode( ' OR ', $validLanguages ) . ')';
        }

        solrTool::solrStopWordsFilter( $params );    //excluding stopwords
        self::parseBooleanOperators( $params );      // translations for bookean operators
        $solrBase = new eZSolrBase( $fullSolrURI );
        $result = $solrBase->rawSolrRequest( '/select', $params, $requestType );
        if ( !$result )
            self::addNoCacheHeaders();
        
        eZDebug::accumulatorStop( __CLASS__ . '::' . __FUNCTION__ );

        return $result;
    }
    /**
     * @param string $clusterIdentifier
     * @throws eZDBException
     */
    public static function fill($clusterIdentifier)
    {
        $configPath = "extension/ezoscar/bin/php/seo/config.json";
        $cli = eZCLI::instance();

        $config = file_get_contents($configPath);
        if(!$config)
        {
            $cli->output("Bad filepath for config file");
            eZExecution::cleanExit();
        }

        $config = json_decode($config, true);

        $db = MMDB::instance();

        $rows = $db->arrayQuery(sprintf("SELECT * FROM mm_seo WHERE cluster_identifier = '%s'", $clusterIdentifier));
        $progressBar = new ezcConsoleProgressbar( new ezcConsoleOutput(), count($rows), array(
            'emptyChar' => ' ',
            'barChar'   => '='
        ) );
        $progressBar->start();

        foreach($rows as $row)
        {
            if(!array_key_exists($clusterIdentifier, $config))
            {
                continue;
            }

            $fq = $config[$clusterIdentifier][$row["application_identifier"]]["filters"];

            $solrBase = new eZSolrBase();
            $params = array(
                'indent'       => 'on',
                'q'            => '"'.$row['keyword'].'"',
                'fq'           => $fq,
                'start'        => 0,
                'rows'         => 0,
                'fl'           => '',
                'qt'           => 'ezpublish',
                'explainOther' => '',
                'hl.fl'        => '',
            );

            $results = $solrBase->rawSolrRequest('/select', $params);
            $num_found = $results['response']['numFound'];
            $db->query(sprintf("UPDATE mm_seo SET nb_results=%d, speciality_url='%s', keyword_url='%s' WHERE id=%d",
                $num_found,
                self::sanitize($row["speciality"]),
                self::sanitize($row["keyword"]),
                $row["id"]));

            $progressBar->advance();
        }
        $progressBar->finish();
        $cli->output();
    }
    /**
     * @param string $clusterIdentifier
     * @param array $applicationIds
     * @throws ezfSolrException
     */
    public static function reindex( $clusterIdentifier, $applicationIds = array() )
    {
        $applicationSearch = new self();
        $solrBase = new eZSolrBase();
        $url = $solrBase->SearchServerURI . '/update';

        // delete all
        $solrBase->sendHTTPRequest( $url, $applicationSearch->bulidDeleteXml( $clusterIdentifier ), 'text/xml' );
        $solrBase->commit();

        // add wanted
        $xml = $applicationSearch->bulidUpdateXml( $clusterIdentifier, $applicationIds );
        $solrBase->sendHTTPRequest( $url, $xml, 'text/xml' );
        $solrBase->commit();
    }
    public function search($remoteId, $nodeId, $language) {
        $queryParameters = array();

        if ($remoteId)
            $queryParameters[] = 'meta_remote_id_ms:' . $remoteId;
        if ($nodeId)
            $queryParameters[] = 'meta_node_id_si:' . $nodeId;
        if ($language)
            $queryParameters[] = 'meta_language_code_ms:' . $language;

        $parameters = array();
        if (count($queryParameters))
            $parameters['q'] = implode(' AND ', $queryParameters);

        $solr = new eZSolrBase(false);
        $rawSearch = $solr->rawSearch($parameters);

        $docs = array();
        if (isset($rawSearch['response']['docs'])) {
            $docs = $rawSearch['response']['docs'];
        }

        return $docs;
    }
示例#5
0
 /**
  *
  * @param eZSolrBase $solrCore the Solr instance to use
  * @param array $fields a hash array in teh form fieldname => fieldvalue (single scalar or array for multivalued fields)
  * @param boolean $commit do a commit or not
  * @param boolean $optimize do an optimize or not, usually false as this can be very CPU intensive
  * @param int $commitWithin optional commitWithin commit window expressed in milliseconds
  * @return boolean success or failure
  */
 public static function addDocument(eZSolrBase $solrCore, $fields = array(), $commit = false, $optimize = false, $commitWithin = 0)
 {
     if (count($fields) == 0) {
         return false;
     }
     $destDoc = new eZSolrDoc();
     foreach ($fields as $fieldName => $fieldValue) {
         $destDoc->addField($fieldName, $fieldValue);
     }
     return $solrCore->addDocs(array($destDoc), $commit, $optimize, $commitWithin);
 }
示例#6
0
 /**
  * Tells whether $coreUrl allows to reach a running Solr.
  * If $coreUrl is false, the default Solr Url from solr.ini is used
  *
  * @param mixed $coreUrl
  * @return bool
  */
 protected function isSolrRunning($coreUrl = false)
 {
     $solrBase = new eZSolrBase($coreUrl);
     $pingResult = $solrBase->ping();
     return isset($pingResult['status']) && $pingResult['status'] === 'OK';
 }
示例#7
0
 /**
  * Test for {@link eZSolrBase::sendHTTPRequest()} with a request that will time out
  * An exception must be thrown in that case
  * @link http://issues.ez.no/17862
  * @group issue17862
  * @expectedException ezfSolrException
  */
 public function testSendHTTPRequestException()
 {
     ezpINIHelper::setINISetting('solr.ini', 'SolrBase', 'SearchServerURI', $this->nonReachableSolr);
     $solrBase = new eZSolrBase();
     $postString = $solrBase->buildPostString($this->postParams);
     $solrBase->sendHTTPRequest($solrBase->SearchServerURI . $this->testURI, $postString);
 }


if ( !$top_node_id )
{
    $cli->error('Please provide a top node id');
    $script->shutdown(1);
}

$script->initialize();

$cli->output('Getting solr results for ' . $top_node_id);

/* @var $solr eZSolr */
$solr = new eZSolr();
$solrBase = new eZSolrBase();

$params = array(
    'indent'       => 'on',
    'q'            => '',
    'fq'           => 'meta_installation_id_ms:' . eZSolr::installationID() . ' AND meta_path_si:' . $top_node_id,
    'start'        => 0,
    'rows'         => 0,
    'fl'           => 'meta_main_url_alias_ms,meta_main_node_id_si,meta_name_t,meta_guid_ms,meta_language_code_ms',
    'qt'           => 'ezpublish',
    'explainOther' => '',
    'hl.fl'        => '',
);

$r = $solrBase->rawSolrRequest('/select', $params);
$num_found = $r['response']['numFound'];
 /**
  * Delete Solr entries with publisher "congress_report_pt"
  */
 protected function deletePreviousArticles()
 {
     $ezSolrBase = new eZSolrBase();
     $ezSolrBase->deleteDocs(array(), 'subattr_publisher_folder___source_id____s:"congress_report_pt"');
 }
示例#10
0
 /**
  * Returns autocomplete suggestions for given params
  *
  * @param mixed $args
  * @return array
  */
 public static function autocomplete($args)
 {
     $result = array();
     $findINI = eZINI::instance('ezfind.ini');
     $solrINI = eZINI::instance('solr.ini');
     $siteINI = eZINI::instance();
     $currentLanguage = $siteINI->variable('RegionalSettings', 'ContentObjectLocale');
     $input = isset($args[0]) ? mb_strtolower($args[0], 'UTF-8') : null;
     $limit = isset($args[1]) ? (int) $args[1] : (int) $findINI->variable('AutoCompleteSettings', 'Limit');
     $facetField = $findINI->variable('AutoCompleteSettings', 'FacetField');
     $params = array('q' => '*:*', 'json.nl' => 'arrarr', 'facet' => 'true', 'facet.field' => $facetField, 'facet.prefix' => $input, 'facet.limit' => $limit, 'facet.mincount' => 1);
     if ($findINI->variable('LanguageSearch', 'MultiCore') == 'enabled') {
         $languageMapping = $findINI->variable('LanguageSearch', 'LanguagesCoresMap');
         $shardMapping = $solrINI->variable('SolrBase', 'Shards');
         $fullSolrURI = $shardMapping[$languageMapping[$currentLanguage]];
     } else {
         $fullSolrURI = $solrINI->variable('SolrBase', 'SearchServerURI');
         // Autocomplete search should be done in current language and fallback languages
         $validLanguages = array_unique(array_merge($siteINI->variable('RegionalSettings', 'SiteLanguageList'), array($currentLanguage)));
         $params['fq'] = 'meta_language_code_ms:(' . implode(' OR ', $validLanguages) . ')';
     }
     $solrBase = new eZSolrBase($fullSolrURI);
     $result = $solrBase->rawSolrRequest('/select', $params, 'json');
     return $result['facet_counts']['facet_fields'][$facetField];
 }
if(!empty($year) && !empty($month))
{
    echo "\n Evrika Calendar URL : " . $merckINI->variable('EvrikaCalendar', 'RSSUrl') . $year . '/' . $month . " \n";
    $evrikaTool = new EvrikaTool($merckINI->variable('EvrikaCalendar', 'RSSUrl') . $year . '/' . $month , 'evrika-calendar', $i);
    $evrikaTool->importXMLToDatabase();
}
else
{
    $importFromMonths = -2;
    $importToMonths = 4;
    
    if( date('N', time()) == 3 )
    {
        echo "\n Remove all solr evrika content \n";
        $solrBase = new eZSolrBase();
        $url = $solrBase->SearchServerURI . '/update';
        // Remove all solr evrika content
        $deleteQuery = '<delete><query>subattr_publisher_folder___source_id____s:evrika_calendar_ru</query></delete>';
        $solrBase->sendHTTPRequest( $url, $deleteQuery, 'text/xml' );
        $solrBase->commit();
        $importFromMonths = -4;
        $importToMonths = 8;
    }

    //import the 8 next months
    for($i=$importFromMonths; $i<$importToMonths; $i++)
    {
        echo "\n Evrika Calendar URL : " . $merckINI->variable('EvrikaCalendar', 'RSSUrl') . date('Y/m', strtotime('+' . $i . ' month')) . " \n";
        $evrikaTool = new EvrikaTool($merckINI->variable('EvrikaCalendar', 'RSSUrl') . date('Y/m', strtotime('+' . $i . ' month')) , 'evrika-calendar', $i);
        $evrikaTool->importXMLToDatabase();
                'rating'    => 'attr_content_rating_'.$row['cluster_identifier'].'_f',
            );

            $params = array(
                'indent'        => 'on',
                'q'             => '*:*',
                'start'         => 0,
                'rows'          => 1,
                'fq'            => 'meta_remote_id_ms:'.$remoteId,
                'fl'            => '',//implode(',', $fields),
                'qt'            => '',
                'explainOther'  => '',
                'hl.fl'         => '',
            );

            $solrBase = new eZSolrBase();
            $result = $solrBase->rawSolrRequest( '/select', $params, 'php' );
            $result['response']['docs'][0]['attr_content_rating_'.$row['cluster_identifier'].'_f'] = $row['total'];

            $solrIndexationJob = new SolrIndexationJob(null);
            $solrIndexationJob->setAttribute('data', json_encode($result['response']['docs'][0]));
            $solrIndexationJob->store();
        }

        $mdb->query(
            sprintf(
                'UPDATE mm_rating_remote SET to_reindex = 0 WHERE remote_id = "%s"',
                $remoteId
            )
        );
    }
示例#13
0
            $xml = array();
            foreach ($xmlData as $doc) {
                if (is_object($doc)) {
                    if (is_object($doc->Doc)) {
                        $doc->Doc->formatOutput = true;
                        $xml[] = $doc->Doc->saveXML($doc->RootElement);
                    } else {
                        $dom = new DOMDocument();
                        $dom->preserveWhiteSpace = FALSE;
                        $dom->loadXML($doc->docToXML());
                        $dom->formatOutput = TRUE;
                        $xml[] = $dom->saveXML($dom->documentElement);
                    }
                }
            }
            $solrBase = new eZSolrBase();
            $version = json_decode(eZHTTPTool::getDataByURL($solrBase->SearchServerURI . '/admin/system/?wt=json'), true);
            $solr = array('ping' => trim(print_r($solrBase->ping(), 1)), 'version' => trim(print_r($version, 1)));
        } else {
            $error = "Current user can not read object {$objectID}";
        }
    } else {
        $error = "Object {$objectID} not found";
    }
}
$tpl->setVariable('error', $error);
$tpl->setVariable('info', $info);
$tpl->setVariable('detail', $detail);
$tpl->setVariable('xml', $xml);
$tpl->setVariable('solr', $solr);
echo $tpl->fetch('design:index/object.tpl');
示例#14
0
 /**
  * Returns autocomplete suggestions for given params
  *
  * @param mixed $args
  * @return array
  */
 public static function autocomplete($args)
 {
     $result = array();
     $findINI = eZINI::instance('ezfind.ini');
     // Only make calls if explicitely enabled
     if ($findINI->hasVariable('AutoCompleteSettings', 'AutoComplete') && $findINI->variable('AutoCompleteSettings', 'AutoComplete') === 'enabled') {
         $solrINI = eZINI::instance('solr.ini');
         $siteINI = eZINI::instance();
         $currentLanguage = $siteINI->variable('RegionalSettings', 'ContentObjectLocale');
         $input = isset($args[0]) ? mb_strtolower($args[0], 'UTF-8') : null;
         $limit = isset($args[1]) ? (int) $args[1] : (int) $findINI->variable('AutoCompleteSettings', 'Limit');
         $facetField = $findINI->variable('AutoCompleteSettings', 'FacetField');
         $facetMethod = $findINI->variable('AutoCompleteSettings', 'FacetMethod');
         $params = array('q' => '*:*', 'rows' => 0, 'json.nl' => 'arrarr', 'facet' => 'true', 'facet.field' => $facetField, 'facet.prefix' => $input, 'facet.limit' => $limit, 'facet.method' => $facetMethod, 'facet.mincount' => 1);
         if ($findINI->variable('LanguageSearch', 'MultiCore') == 'enabled') {
             $languageMapping = $findINI->variable('LanguageSearch', 'LanguagesCoresMap');
             $shardMapping = $solrINI->variable('SolrBase', 'Shards');
             $fullSolrURI = $shardMapping[$languageMapping[$currentLanguage]];
         } else {
             $fullSolrURI = $solrINI->variable('SolrBase', 'SearchServerURI');
             // Autocomplete search should be done in current language and fallback languages
             $validLanguages = array_unique(array_merge($siteINI->variable('RegionalSettings', 'SiteLanguageList'), array($currentLanguage)));
             $params['fq'] = 'meta_language_code_ms:(' . implode(' OR ', $validLanguages) . ')';
         }
         //build the query part for the subtree limitation
         if (isset($args[2]) && (int) $args[2]) {
             if (isset($params['fq']) && $params['fq']) {
                 $params['fq'] .= ' AND ';
             }
             $params['fq'] .= eZSolr::getMetaFieldName('path') . ':' . (int) $args[2];
         }
         //build the query part for the class limitation
         if (isset($args[3]) && $args[3]) {
             if (isset($params['fq']) && $params['fq']) {
                 $params['fq'] .= ' AND ';
             }
             $classes = explode(',', $args[3]);
             $classQueryParts = array();
             foreach ($classes as $class) {
                 if (!is_numeric($class)) {
                     if ($class = eZContentClass::fetchByIdentifier($class)) {
                         $classQueryParts[] = eZSolr::getMetaFieldName('contentclass_id') . ':' . $class->attribute('id');
                     }
                 } else {
                     $classQueryParts[] = eZSolr::getMetaFieldName('contentclass_id') . ':' . $class;
                 }
             }
             $classQueryParts = implode(' OR ', $classQueryParts);
             $params['fq'] .= '(' . $classQueryParts . ')';
         }
         $solrBase = new eZSolrBase($fullSolrURI);
         $result = $solrBase->rawSolrRequest('/select', $params, 'json');
         return $result['facet_counts']['facet_fields'][$facetField];
     } else {
         // not enabled, just return an empty array
         return array();
     }
 }
示例#15
0
 /**
  * Send an HTTP Get query to Solr engine
  *
  * @param string $request request name
  * @param string $getParams HTTP GET parameters, as an associative array
  *
  * @return Result of HTTP Request ( without HTTP headers )
  */
 function getQuery($request, $getParams)
 {
     return $this->sendHTTPRequestRetry(eZSolrBase::buildHTTPGetQuery($request, $getParams));
 }
 /**
  * Pushes the configuration XML to Solr through a custom requestHandler ( HTTP/ReST ).
  * The requestHandler ( Solr extension ) will take care of reloading the configuration.
  *
  * @see $configurationXML
  * @return void
  */
 protected static function pushConfigurationToSolr($shard = null)
 {
     $params = array('qt' => 'ezfind', self::CONF_PARAM_NAME => self::getConfiguration());
     // Keep previous behaviour, but should not be needed
     if ($shard === null) {
         $shard = new eZSolrBase();
     }
     $result = $shard->pushElevateConfiguration($params);
     if (!$result) {
         $message = ezpI18n::tr('extension/ezfind/elevate', 'An unknown error occured in updating Solr\'s elevate configuration.');
         eZDebug::writeError($message, __METHOD__);
         throw new Exception($message);
     } elseif (isset($result['error'])) {
         eZDebug::writeError($result['error'], __METHOD__);
         throw new Exception($result['error']);
     } else {
         eZDebug::writeNotice("Successful update of Solr's configuration.", __METHOD__);
     }
 }
示例#17
0
    /**
     * rawSolrRequest function
     *
     * @param base specifies the Solr server/shard to use
     * @param request the base request
     * @param parameters all parameters for the request
     *
     * @return array result as a PHP array
     */
    public function rawSolrRequest( $baseURI, $request, $parameters = array() )
    {

        $solr = new eZSolrBase( $baseURI );
        return array( 'result' => $solr->rawSolrRequest( $request, $parameters ) );
    }
示例#18
0
文件: index.php 项目: truffo/eep
 private function isSolrRunning()
 {
     // ping solr, to find out if it is (already) running
     $ini = eZINI::instance('solr.ini');
     $url = $ini->variable('SolrBase', 'SearchServerURI');
     $solrBase = new eZSolrBase($url);
     $pingResult = $solrBase->ping();
     return isset($pingResult['status']) && $pingResult['status'] === 'OK';
 }