Jdouglas has uploaded a new change for review.
https://gerrit.wikimedia.org/r/194950
Change subject: Factor out insource fallthrough
......................................................................
Factor out insource fallthrough
This gathers code common to the insource and intitle cases under a new
TermQuery class, which can be accessed via its public insource() and intitle()
functions.
The new functions are all side-effect-free, and return a side-effecting
lambda updateReferences(), which can later called with the references to be
updated.
Change-Id: I507c1a75f668596fbfa4b391acb9c7ff5685ab13
---
M includes/Searcher.php
1 file changed, 50 insertions(+), 24 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch
refs/changes/50/194950/1
diff --git a/includes/Searcher.php b/includes/Searcher.php
index 6e6cd6b..d6a3d9e 100644
--- a/includes/Searcher.php
+++ b/includes/Searcher.php
@@ -536,31 +536,12 @@
$searchContainedSyntax = true;
return '';
case 'insource':
- $field = 'source_text.plain';
- $keepText = false;
- // intentionally fall through
+ $updateReferences =
TermQuery::insource( $escaper, $searcher, $value );
+ $updateReferences( $fuzzyQuery,
$filterDestination, $highlightSource, $searchContainedSyntax );
+ return '';
case 'intitle':
- list( $queryString, $fuzzyQuery
) = $escaper->fixupWholeQueryString(
-
$escaper->fixupQueryStringPart( $value ) );
- if ( !isset( $field ) ) {
- if ( preg_match(
'/[?*]/u', $queryString ) ) {
- $field =
'title.plain';
- } else {
- $field =
'title';
- }
- }
- $query = new
\Elastica\Query\QueryString( $queryString );
- $query->setFields( array(
$field ) );
- $query->setDefaultOperator(
'AND' );
-
$query->setAllowLeadingWildcard( false );
- $query->setFuzzyPrefixLength( 2
);
- $query->setRewrite(
'top_terms_128' );
- $query =
$searcher->wrapInSaferIfPossible( $query, false );
- $filterDestination[] = new
\Elastica\Filter\Query( $query );
- if ( $key === 'insource' ) {
- $highlightSource[] =
array( 'query' => $query );
- }
- $searchContainedSyntax = true;
+ $updateReferences =
TermQuery::intitle( $escaper, $searcher, $value );
+ $updateReferences( $fuzzyQuery,
$filterDestination, $highlightSource, $searchContainedSyntax );
return $keepText ? "$value " :
'';
default:
return $matches[0];
@@ -1510,3 +1491,48 @@
$this->namespaces = array( $foundNamespace->getId() );
}
}
+
+class TermQuery {
+
+ public static function insource( $escaper, $searcher, $value ) {
+ $fieldF = function () {
+ return 'source_text.plain';
+ };
+ return self::insourceOrIntitle( $escaper, $searcher, $value,
$fieldF );
+ }
+
+ public static function intitle( $escaper, $searcher, $value ) {
+ $fieldF = function ( $queryString ) {
+ if ( preg_match( '/[?*]/u', $queryString ) ) {
+ return 'title.plain';
+ } else {
+ return 'title';
+ }
+ };
+ return self::insourceOrIntitle( $escaper, $searcher, $value,
$fieldF );
+ }
+
+ private static function insourceOrIntitle( $escaper, $searcher, $value,
$fieldF ) {
+ list( $queryString, $fuzzyQuery ) =
$escaper->fixupWholeQueryString(
+ $escaper->fixupQueryStringPart( $value ) );
+ $field = $fieldF( $queryString );
+ $query = new \Elastica\Query\QueryString( $queryString );
+ $query->setFields( array( $field ) );
+ $query->setDefaultOperator( 'AND' );
+ $query->setAllowLeadingWildcard( false );
+ $query->setFuzzyPrefixLength( 2 );
+ $query->setRewrite( 'top_terms_128' );
+ $wrappedQuery = $searcher->wrapInSaferIfPossible( $query, false
);
+
+ $updateReferences =
+ function ( &$fuzzyQueryRef, &$filterDestinationRef,
&$highlightSourceRef, &$searchContainedSyntaxRef ) use ( $fuzzyQuery,
$wrappedQuery ) {
+ $fuzzyQueryRef = $fuzzyQuery;
+ $filterDestinationRef[] = new
\Elastica\Filter\Query( $wrappedQuery );
+ $highlightSourceRef[] = array( 'query' =>
$wrappedQuery );
+ $searchContainedSyntaxRef = true;
+ };
+
+ return $updateReferences;
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/194950
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I507c1a75f668596fbfa4b391acb9c7ff5685ab13
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Jdouglas <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits