Smalyshev has uploaded a new change for review.
https://gerrit.wikimedia.org/r/281077
Change subject: [WIP] Add deleted archive titles search
......................................................................
[WIP] Add deleted archive titles search
Bug: T109561
Change-Id: I48382f24d91b4421b6a1754d7f30c18b173263db
---
M includes/CirrusSearch.php
M includes/Searcher.php
2 files changed, 54 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch
refs/changes/77/281077/1
diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php
index bd279e6..ba28a81 100644
--- a/includes/CirrusSearch.php
+++ b/includes/CirrusSearch.php
@@ -665,4 +665,31 @@
return SearchSuggestionSet::emptySuggestionSet();
}
+
+ /**
+ * Perform a title search in the article archive.
+ *
+ * @param string $term Raw search term
+ * @return Title[]|Status|null
+ */
+ function searchArchiveTitle ( $term ) {
+ $term = trim( $term );
+
+ if ( empty($term) ) {
+ return null;
+ }
+
+ $title = Title::newFromText( $term );
+ if ( $title ) {
+ $ns = $title->getNamespace();
+ $term = $title->getText();
+ } else {
+ $ns = NS_MAIN;
+ }
+
+ $searcher = new Searcher( $this->connection, $this->offset,
$this->limit, null, [ $ns ], null, $this->indexBaseName );
+ $status = $searcher->searchArchive( $term );
+ return $status->isOk() ? $status->getValue() : $status;
+ }
+
}
diff --git a/includes/Searcher.php b/includes/Searcher.php
index 042cf37..41703af 100644
--- a/includes/Searcher.php
+++ b/includes/Searcher.php
@@ -8,6 +8,7 @@
use CirrusSearch\Search\Escaper;
use CirrusSearch\Search\Filters;
use CirrusSearch\Search\FullTextResultsType;
+use CirrusSearch\Search\TitleResultsType;
use CirrusSearch\Search\ResultsType;
use CirrusSearch\Search\RescoreBuilder;
use CirrusSearch\Search\SearchContext;
@@ -1176,7 +1177,11 @@
$this->connection->setTimeout( $queryOptions[ 'timeout' ] );
// Setup the search
- $pageType = $this->connection->getPageType(
$this->indexBaseName, $indexType );
+ if( $this->pageType ) {
+ $pageType = $this->pageType;
+ } else {
+ $pageType = $this->connection->getPageType(
$this->indexBaseName, $indexType );
+ }
$search = $pageType->createSearch( $query, $queryOptions );
foreach ( $extraIndexes as $i ) {
$search->addIndex( $i );
@@ -1658,4 +1663,25 @@
return $this->searchContext;
}
+ /**
+ * Search titles in archive
+ * @param string $term
+ * @return Status|Title[]
+ */
+ public function searchArchive( $term ) {
+ list($term, $fuzzy) = $this->escaper->fixupWholeQueryString(
$term );
+ $this->resultsType = new TitleResultsType();
+ $this->filters[] = new Elastica\Filter\Terms( 'wiki', [
$this->indexBaseName ]);
+ $this->pageType = $this->connection->getPageType( 'archive' );
+ $this->query = $this->buildSearchTextQueryForFields([ 'title'
], $term . '~', 0, false);
+ $this->sort = 'incoming_links_desc';
+ $this->limitSearchToLocalWiki = true;
+ $result = $this->search( 'archive', $term );
+ //echo "<pre>";var_dump($result); exit();
+ if($result->isOK()) {
+ return $this->success( $result->getValue() );
+ }
+ return $result;
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/281077
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I48382f24d91b4421b6a1754d7f30c18b173263db
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits