当前位置: 首页>>代码示例>>PHP>>正文


PHP Solarium_Client::createMoreLikeThis方法代码示例

本文整理汇总了PHP中Solarium_Client::createMoreLikeThis方法的典型用法代码示例。如果您正苦于以下问题:PHP Solarium_Client::createMoreLikeThis方法的具体用法?PHP Solarium_Client::createMoreLikeThis怎么用?PHP Solarium_Client::createMoreLikeThis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Solarium_Client的用法示例。


在下文中一共展示了Solarium_Client::createMoreLikeThis方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: moreLikeThis

 /**
  * Utilizes Solr's MoreLikeThis component to return similar pages
  * @see    WikiaSearchTest::testMoreLikeThis
  * @param  WikiaSearchConfig $searchConfig
  * @return WikiaSearchResultSet
  */
 private function moreLikeThis(WikiaSearchConfig $searchConfig)
 {
     $query = $searchConfig->getQuery(WikiaSearchConfig::QUERY_RAW);
     $streamBody = $searchConfig->getStreamBody();
     $streamUrl = $searchConfig->getStreamUrl();
     if (!($query || $streamBody || $streamUrl)) {
         throw new Exception("A query, url, or stream is required.");
     }
     $mlt = $this->client->createMoreLikeThis();
     $mlt->setMltFields(implode(',', $searchConfig->getMltFields()))->setFields($searchConfig->getRequestedFields())->addParam('mlt.match.include', 'false')->setStart($searchConfig->getStart())->setRows($searchConfig->getRows())->setDocumentClass('WikiaSearchResult');
     if ($searchConfig->getInterestingTerms() == 'list') {
         $mlt->setInterestingTerms('list');
     }
     if ($searchConfig->getMltFilterQuery()) {
         $mlt->addFilterQuery(array('query' => $searchConfig->getMltFilterQuery(), 'key' => 'mltfilterquery'));
     }
     if ($query !== null) {
         $mlt->setQuery($query);
     } else {
         if ($streamBody) {
             $mlt->addParam('stream.body', $streamBody);
         } else {
             if ($streamUrl) {
                 $mlt->addParam('stream.url', $streamUrl);
             }
         }
     }
     try {
         $mltResult = $this->client->moreLikeThis($mlt);
     } catch (Exception $e) {
         $mltResult = F::build('Solarium_Result_Select_Empty');
         Wikia::Log(__METHOD__, '', $e);
     }
     $results = F::build('WikiaSearchResultSet', array($mltResult, $searchConfig));
     return $results;
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:42,代码来源:WikiaSearch.class.php

示例2: StdClass

 /**
  * Get a collection of the laws most similar to the present law.
  */
 function get_related()
 {
     /*
      * The number of results to return. The default is 5.
      */
     if (!isset($this->num_results)) {
         $this->num_results = 5;
     }
     /*
      * Intialize Solarium.
      */
     $client = new Solarium_Client($GLOBALS['solr_config']);
     if ($client === FALSE) {
         return FALSE;
     }
     /*
      * Create a MoreLikeThis query instance.
      */
     $query = $client->createMoreLikeThis();
     /*
      * Note that we have to escape colons in this query.
      */
     $query->setQuery('section:' . str_replace(':', '\\:', $this->section_number));
     $query->setMltFields('text,tags,catch_line');
     $query->setMatchInclude(TRUE);
     $query->setStart(0)->setRows($this->num_results);
     /*
      * Execute the query and return the result.
      */
     $results = $client->select($query);
     /*
      * If our query fails.
      */
     if ($results === FALSE) {
         return FALSE;
     }
     /*
      * Create a new, blank object to store our related sections.
      */
     $related = new StdClass();
     /*
      * Iterate through the returned documents
      */
     $i = 0;
     foreach ($results as $document) {
         $law = new Law();
         $law->law_id = $document->id;
         $law->get_law();
         $related->{$i} = $law;
         $i++;
     }
     return TRUE;
 }
开发者ID:FreeLawFounders,项目名称:statedecoded,代码行数:56,代码来源:class.Law.inc.php

示例3: implode

<?php

require 'init.php';
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get a morelikethis query instance
$query = $client->createMoreLikeThis();
$query->setQuery('id:SP2514N');
$query->setMltFields('manu,cat');
$query->setMinimumDocumentFrequency(1);
$query->setMinimumTermFrequency(1);
$query->createFilterQuery('stock')->setQuery('inStock:true');
$query->setInterestingTerms('details');
$query->setMatchInclude(true);
// this executes the query and returns the result
$resultset = $client->select($query);
echo 'Document used for matching:<br/><table>';
foreach ($resultset->getMatch() as $field => $value) {
    // this converts multivalue fields to a comma-separated string
    if (is_array($value)) {
        $value = implode(', ', $value);
    }
    echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}
echo '</table><hr/>';
// display the total number of MLT documents found by solr
echo 'Number of MLT matches found: ' . $resultset->getNumFound() . '<br/><br/>';
echo '<b>Listing of matched docs:</b>';
// show MLT documents using the resultset iterator
foreach ($resultset as $document) {
开发者ID:swapnilphalak,项目名称:crawl-anywhere,代码行数:31,代码来源:2.3.1-mlt-query.php


注:本文中的Solarium_Client::createMoreLikeThis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。