Manybubbles has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/135038

Change subject: Add more parameters to skip highlighting
......................................................................

Add more parameters to skip highlighting

This allows you to skip it all together which might be a useful test.

Change-Id: I1523fdf58f3d5d1310994a82e2b3dcb74aac44ec
---
M includes/CirrusSearch.php
M includes/ResultsType.php
M includes/Searcher.php
3 files changed, 37 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch 
refs/changes/38/135038/1

diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php
index 6eed431..460cde8 100644
--- a/includes/CirrusSearch.php
+++ b/includes/CirrusSearch.php
@@ -102,9 +102,17 @@
                        if ( $request && $request->getVal( 
'cirrusSuppressSuggest' ) !== null ) {
                                $this->showSuggestion = false;
                        }
-                       if ( $request && $request->getVal( 
'cirrusSuppressSnippet' ) !== null ) {
-                               $searcher->setResultsType( new 
FullTextResultsType( false ) );
+                       $highlightingConfig = 
FullTextResultsType::HIGHLIGHT_ALL;
+                       if ( $request && $request->getVal( 
'cirrusSuppressTitleHighlight' ) !== null ) {
+                               $highlightingConfig ^= 
FullTextResultsType::HIGHLIGHT_TITLE;
                        }
+                       if ( $request && $request->getVal( 
'cirrusSuppressAltTitle' ) !== null ) {
+                               $highlightingConfig ^= 
FullTextResultsType::HIGHLIGHT_ALT_TITLE;
+                       }
+                       if ( $request && $request->getVal( 
'cirrusSuppressSnippet' ) !== null ) {
+                               $highlightingConfig ^= 
FullTextResultsType::HIGHLIGHT_SNIPPET;
+                       }
+                       $searcher->setResultsType( new FullTextResultsType( 
$highlightingConfig ) );
                        $status = $searcher->searchText( $term, 
$this->showSuggestion );
                }
 
diff --git a/includes/ResultsType.php b/includes/ResultsType.php
index a339340..1492a40 100644
--- a/includes/ResultsType.php
+++ b/includes/ResultsType.php
@@ -147,11 +147,23 @@
        }
 }
 
+/**
+ * Result type for a full text search.
+ */
 class FullTextResultsType implements ResultsType {
-       private $showTextHighlighting;
+       const HIGHLIGHT_NONE = 0;
+       const HIGHLIGHT_TITLE = 1;
+       const HIGHLIGHT_ALT_TITLE = 2;
+       const HIGHLIGHT_SNIPPET = 4;
+       const HIGHLIGHT_ALL = 7;
 
-       public function __construct( $showTextHighlighting ) {
-               $this->showTextHighlighting = $showTextHighlighting;
+       private $highlightingConfig;
+
+       /**
+        * @param bitmask $highlightingConfig see HIGHLIGHT_* consts
+        */
+       public function __construct( $highlightingConfig ) {
+               $this->highlightingConfig = $highlightingConfig;
        }
 
        public function getSourceFiltering() {
@@ -236,19 +248,25 @@
                $config =  array(
                        'pre_tags' => array( Searcher::HIGHLIGHT_PRE ),
                        'post_tags' => array( Searcher::HIGHLIGHT_POST ),
-                       'fields' => $this->addMatchedFields( array(
-                               'title' => $entireValue,
+                       'fields' => array(),
+               );
+               if ( $this->highlightingConfig & 
FullTextResultsType::HIGHLIGHT_TITLE ) {
+                       $config[ 'fields' ][ 'title' ] = $entireValue;
+               }
+               if ( $this->highlightingConfig & 
FullTextResultsType::HIGHLIGHT_ALT_TITLE ) {
+                       $config[ 'fields' ] = array_merge( $config[ 'fields' ], 
array(
                                'redirect.title' => $entireValueInListField,
                                'heading' => $entireValueInListField,
-                       ) ),
-               );
-               if ( $this->showTextHighlighting ) {
+                       ) );
+               }
+               if ( $this->highlightingConfig & 
FullTextResultsType::HIGHLIGHT_SNIPPET ) {
                        $config[ 'fields' ] = array_merge( $config[ 'fields' ], 
array(
                                'text' => $text,
                                'auxiliary_text' => $singleFragment,
                                'file_text' => $singleFragment,
                        ) );
                }
+               $config[ 'fields' ] = $this->addMatchedFields( $config[ 
'fields' ] );
                return $config;
        }
 
diff --git a/includes/Searcher.php b/includes/Searcher.php
index 63cf5c5..714e8f7 100644
--- a/includes/Searcher.php
+++ b/includes/Searcher.php
@@ -684,7 +684,7 @@
                $profiler = new ProfileSection( __METHOD__ );
 
                if ( $this->resultsType === null ) {
-                       $this->resultsType = new FullTextResultsType( true );
+                       $this->resultsType = new FullTextResultsType( 
FullTextResultsType::HIGHLIGHT_ALL );
                }
                // Default null queries now so the rest of the method can 
assume it is not null.
                if ( $this->query === null ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/135038
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1523fdf58f3d5d1310994a82e2b3dcb74aac44ec
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <never...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to