Esempio n. 1
0
 /**
  * Accesses backlinks. Iterate over a result set of documents with outbound links, and store.
  * (non-PHPdoc)
  * @see \Wikia\Search\IndexService\AbstractService::execute()
  */
 public function execute()
 {
     $docIdSeparated = $this->getCurrentDocumentId() . ' |';
     $config = new Config();
     $config->setDirectLuceneQuery(true)->setQuery(sprintf('outbound_links_txt:"%s"', $docIdSeparated));
     $factory = new Factory();
     $backlinks = [];
     do {
         $offset = 0;
         $limit = 100;
         $config->setStart($offset)->setLimit($limit);
         $resultSet = $factory->getFromConfig($config)->search();
         foreach ($resultSet as $result) {
             foreach ($result['outbound_links_txt'] as $link) {
                 if (substr($link, 0, strlen($docIdSeparated)) == $docIdSeparated) {
                     $backlinks[] = implode(' | ', array_slice(explode(' | ', $link), 1));
                 }
             }
         }
         $offset = $limit;
         $limit = $offset + 100;
     } while ($config->getResultsFound() > $limit);
     return ['backlinks_txt' => $backlinks];
 }
Esempio n. 2
0
 /**
  * Responsible for the initial query to Solr, with some error handling built in
  * @return Solarium_Result_Select
  */
 protected function sendSearchRequestToClient()
 {
     try {
         return $this->getClient()->select($this->getSelectQuery());
     } catch (\Exception $e) {
         if ($this->config->getError() !== null) {
             $this->config->setError($e);
             return new \Solarium_Result_Select_Empty();
         } else {
             $this->config->setSkipBoostFunctions(true)->setError($e);
             return $this->sendSearchRequestToClient();
         }
     }
 }
 /**
  * Inspects request and sets config accordingly.
  * @return Wikia\Search\Config
  */
 protected function getConfigFromRequest()
 {
     $request = $this->getRequest();
     $limit = self::POPULAR_ARTICLES_PER_WIKI;
     $baseArticleId = $request->getVal(self::PARAMETER_BASE_ARTICLE_ID, false);
     if ($baseArticleId !== false) {
         $limit = self::TRENDING_ARTICLES_LIMIT;
     }
     $searchConfig = new Wikia\Search\Config();
     $searchConfig->setLimit($limit)->setRank(\Wikia\Search\Config::RANK_MOST_VIEWED)->setOnWiki(true)->setNamespaces([self::POPULAR_ARTICLES_NAMESPACE])->setQuery('*')->setMainPage(false);
     return $searchConfig;
 }
 protected function getConfigById($wikiId, $articleId)
 {
     $searchConfig = new Config();
     $searchConfig->setQuery('*')->setLimit(1)->setPage(1)->setWikiId((int) $wikiId)->setVideoSearch(false)->setOnWiki(true)->setPageId((int) $articleId)->setNamespaces([self::NAMESPACE_SETTING]);
     return $searchConfig;
 }
 protected function getTopArticles($wikiId, $lang)
 {
     return \WikiaDataAccess::cache(wfSharedMemcKey("CombinedSearchService", $wikiId, $lang), self::TOP_ARTICLES_CACHE_TIME, function () use($wikiId, $lang) {
         $timer = Time::start(["CombinedSearchService", "getTopArticles"]);
         $requestedFields = ["title", "url", "id", "score", "pageid", "lang", "wid", "article_quality_i", Utilities::field('html', $lang)];
         $topArticlesMap = \DataMartService::getTopArticlesByPageview($wikiId, null, [NS_MAIN], false, self::TOP_ARTICLES_PER_WIKI + 1);
         $query = " +(" . Utilities::valueForField("wid", $wikiId) . ") ";
         $query .= " +( " . implode(" OR ", array_map(function ($x) {
             return Utilities::valueForField("pageid", $x);
         }, array_keys($topArticlesMap))) . ") ";
         $query .= " +(is_main_page:false) ";
         $searchConfig = new Config();
         $searchConfig->setLimit(self::TOP_ARTICLES_PER_WIKI)->setQuery($query)->setPage(1)->setRequestedFields($requestedFields)->setDirectLuceneQuery(true)->setWikiId($wikiId);
         $resultSet = (new Factory())->getFromConfig($searchConfig)->search();
         $currentResults = $resultSet->toArray($requestedFields);
         $articles = [];
         foreach ($currentResults as $article) {
             $articles[$article['pageid']] = $this->processArticle($article);
             if (sizeof($articles) >= self::TOP_ARTICLES_PER_WIKI) {
                 break;
             }
         }
         $result = [];
         foreach ($topArticlesMap as $id => $a) {
             if (isset($articles[$id])) {
                 $result[] = $articles[$id];
             }
         }
         $timer->stop();
         return $result;
     });
 }
 /**
  * Returns wikia Config for cross wiki search build on request data
  * @return Wikia\Search\Config
  */
 protected function getConfigCrossWiki()
 {
     $request = $this->getRequest();
     $searchConfig = new Wikia\Search\Config();
     $lang = $request->getArray('lang');
     if (in_array(self::ALL_LANGUAGES_STR, $lang)) {
         $lang = ['*'];
     }
     $searchConfig->setQuery($request->getVal('query', null))->setLimit($request->getInt('limit', static::CROSS_WIKI_LIMIT))->setPage($request->getVal('batch', 1))->setRank($request->getVal('rank', 'default'))->setHub($request->getArray('hub', null))->setInterWiki(true)->setCommercialUse($this->hideNonCommercialContent());
     if (!empty($lang)) {
         $searchConfig->setLanguageCode($lang);
     }
     //this will set different boosting
     $searchConfig->setBoostGroup('CrossWikiApi');
     return $searchConfig;
 }
Esempio n. 7
0
 /**
  * @group Slow
  * @slowExecutionTime 0.07594 ms
  * @covers Wikia\Search\Config::getResultsFound
  */
 public function testGetResultsFound()
 {
     $config = new Config();
     $this->assertEquals(0, $config->getResultsFound(), 'With no result set, config should say results found is zero');
     $results = $this->getMockBuilder('Wikia\\Search\\ResultSet\\Base')->disableOriginalConstructor()->setMethods(['getResultsFound'])->getMock();
     $results->expects($this->once())->method('getResultsFound')->will($this->returnValue(100));
     $config->setResults($results);
     $this->assertEquals(100, $config->getResultsFound());
 }
Esempio n. 8
0
 /**
  * @group Slow
  * @slowExecutionTime 0.07538 ms
  * @covers \Wikia\Search\Config::getQuery
  */
 public function testGetQuery()
 {
     $config = new \Wikia\Search\Config();
     $this->assertNull($config->getQuery());
     $query = "foo and: bar & baz";
     $config->setQuery($query);
     $this->assertInstanceOf('Wikia\\Search\\Query\\Select', $config->getQuery());
     $this->assertAttributeContains($query, 'rawQuery', $config->getQuery());
     $config = new \Wikia\Search\Config(['query' => 'foo']);
     $this->assertInstanceOf('Wikia\\Search\\Query\\Select', $config->getQuery());
 }
Esempio n. 9
0
 /**
  * Returns the query used to get these results
  * @return string
  */
 public function getQuery()
 {
     return $this->searchConfig->getQuery()->getQueryForHtml();
 }