Smuggli has submitted this change and it was merged.

Change subject: Added boost query for namespace evaluation
......................................................................


Added boost query for namespace evaluation

Switched from Lucene query parser to ExtendedDisMax query parser. The 
ExtendedDisMax has a lot of new search functionality like boost queries and 
supports the full Lucene query parser syntax, so that non of our functionality 
will break.

From now on we can improve, for example, the evaluation of namespace, to 
provide individual scoring.

 * Improved logging in case of a bad request
 * Readded quotations to prevent query breaking
 * Removed whitespace

Change-Id: I9f7a8fd300d30372f3987af44e1904f238f3a978
---
M ExtendedSearch/includes/SearchIndex/SearchIndex.class.php
M ExtendedSearch/includes/SearchIndex/SearchOptions.class.php
M ExtendedSearch/includes/SolrPhpClient/Response.php
M ExtendedSearch/includes/SolrPhpClient/Service.php
4 files changed, 61 insertions(+), 55 deletions(-)

Approvals:
  Smuggli: Verified; Looks good to me, approved



diff --git a/ExtendedSearch/includes/SearchIndex/SearchIndex.class.php 
b/ExtendedSearch/includes/SearchIndex/SearchIndex.class.php
index 771da7d..6d1aa71 100644
--- a/ExtendedSearch/includes/SearchIndex/SearchIndex.class.php
+++ b/ExtendedSearch/includes/SearchIndex/SearchIndex.class.php
@@ -115,8 +115,7 @@
                                $query['searchOptions']
                        );
                } catch ( Exception $e ) {
-                       // bs-extendedsearch-invalid-query
-                       if ( $e->getMessage() == '"0" Status: Communication 
Error' ) {
+                       if ( stripos( $e->getMessage(), 'Communication Error' ) 
!== false ) {
                                $sUrl = SpecialPage::getTitleFor( 'Search' 
)->getFullURL();
 
                                $sParams = 'search='.urlencode( 
$this->oSearchOptions->getOption( 'searchStringRaw' ) );
@@ -129,6 +128,7 @@
                                return $this->oContext->getOutput()->redirect( 
$sUrl, '404' );
                        }
 
+                       wfDebugLog( 'ExtendedSearch', $e->getMessage() );
                        return $this->createErrorMessageView( 
'bs-extendedsearch-invalid-query' );
                }
 
diff --git a/ExtendedSearch/includes/SearchIndex/SearchOptions.class.php 
b/ExtendedSearch/includes/SearchIndex/SearchOptions.class.php
index 2d7ba23..1476f41 100644
--- a/ExtendedSearch/includes/SearchIndex/SearchOptions.class.php
+++ b/ExtendedSearch/includes/SearchIndex/SearchOptions.class.php
@@ -290,15 +290,21 @@
         * Processes incoming search request
         */
        public function readInSearchRequest() {
-               global $wgCanonicalNamespaceNames, $wgExtraNamespaces;
+               global $wgCanonicalNamespaceNames, $wgExtraNamespaces, 
$wgContentNamespaces;
                $this->aOptions['searchStringRaw'] = 
$this->oSearchRequest->sInput;
                $this->aOptions['searchStringOrig'] = 
ExtendedSearchBase::preprocessSearchInput( $this->oSearchRequest->sInput );
 
                self::$searchStringRaw = $this->aOptions['searchStringRaw'];
 
                $sCustomerId = $this->getCustomerId();
-
+               $sLogOp = ' OR ';
                $aFq = array();
+               $aBq = array();
+
+               $scope = ( BsConfig::get( 'MW::ExtendedSearch::DefScopeUser' ) 
== 'title' )
+                       ? 'title'
+                       : 'text';
+               $this->aOptions['scope'] = $scope;
 
                $vNamespace = $this->checkSearchstringForNamespace(
                        $this->aOptions['searchStringRaw'],
@@ -309,12 +315,6 @@
 
                $this->aOptions['searchStringWildcarded'] = 
SearchService::wildcardSearchstring( $this->aOptions['searchStringOrig'] );
                $this->aOptions['searchStringForStatistics'] = 
$this->aOptions['searchStringWildcarded'];
-               $this->aOptions['bExtendedForm'] = 
$this->oSearchRequest->bExtendedForm;
-
-               $scope = ( BsConfig::get( 'MW::ExtendedSearch::DefScopeUser' ) 
== 'title' )
-                       ? 'title'
-                       : 'text';
-               $this->aOptions['scope'] = $scope;
 
                $aSearchTitle = array(
                        'title:(' . $this->aOptions['searchStringOrig'] . ')^2',
@@ -328,20 +328,20 @@
                        'sections:(' . $this->aOptions['searchStringOrig'] . ')'
                );
 
-               $sSearchStringTitle = implode( ' OR ', $aSearchTitle );
-               $sSearchStringText = implode( ' OR ', $aSearchText );
+               $sSearchStringTitle = implode( $sLogOp, $aSearchTitle );
+               $sSearchStringText = implode( $sLogOp, $aSearchText );
 
                $this->aOptions['searchStringFinal'] = ( 
$this->aOptions['scope'] === 'title' )
                        ? $sSearchStringTitle
-                       : $sSearchStringTitle . ' OR ' . $sSearchStringText;
-
-               // $this->aOptions['namespaces'] HAS TO BE an array with 
numeric indices of type string!
-               $this->aOptions['namespaces'] = 
$this->oSearchRequest->aNamespaces;
+                       : $sSearchStringTitle . $sLogOp . $sSearchStringText;
 
                // filter query
                $aFq[] = 'redirect:0';
                $aFq[] = 'special:0';
                $aFq[] = 'wiki:('.$sCustomerId.')';
+
+               // $this->aOptions['namespaces'] HAS TO BE an array with 
numeric indices of type string!
+               $this->aOptions['namespaces'] = 
$this->oSearchRequest->aNamespaces;
 
                $aNamespaces = array_slice( $wgCanonicalNamespaceNames, 2 );
                $aNamespaces = $aNamespaces + $wgExtraNamespaces;
@@ -434,35 +434,28 @@
 
                // $this->aOptions['cats'] = $this->oSearchRequest->sCat; // 
string, defaults to '' if 'search_cat' not set in REQUEST
                $this->aOptions['cats'] = $this->oSearchRequest->sCategories; 
// array of strings or empty array
-
-               $sOperator = ' OR ';
                if ( !empty( $this->aOptions['cats'] ) ) {
                        if ( isset( $this->oSearchRequest->sOperator ) ) {
                                switch ( $this->oSearchRequest->sOperator ) {
                                        case 'AND':
-                                               $sOperator = ' AND ';
-                                               break;
-                                       case 'OR':
-                                               $sOperator = ' OR ';
+                                               $sLogOp = ' AND ';
                                                break;
                                        default:
                                }
                        }
                        $sFqCategories = ( BsConfig::get( 
'MW::ExtendedSearch::ShowFacets' ) ) ? '{!tag=ca}' : '';
-                       $sFqCategories .= 'cat:("' . implode( '"' . $sOperator 
. '"', $this->aOptions['cats'] ) . '")';
+                       $sFqCategories .= 'cat:("' . implode( '"' . $sLogOp . 
'"', $this->aOptions['cats'] ) . '")';
                        $aFq[] = $sFqCategories;
                }
 
                $this->aOptions['type'] = $this->oSearchRequest->aType;
-
                if ( !empty( $this->aOptions['type'] ) ) {
                        $sFqType = ( BsConfig::get( 
'MW::ExtendedSearch::ShowFacets' ) ) ? '{!tag=ty}' : '';
-                       $sFqType .= 'type:(' . implode( ' OR ', 
$this->aOptions['type'] ) . ')';
+                       $sFqType .= 'type:("' . implode( '"' . $sLogOp . '"', 
$this->aOptions['type'] ) . '")';
                        $aFq[] = $sFqType;
                }
 
                $this->aOptions['editor'] = $this->oSearchRequest->sEditor;
-
                if ( !empty( $this->aOptions['editor'] ) ) {
                        // there may be spaces in name of editor. solr analyses 
those to two
                        // terms (editor's names) thus we wrap the name into 
quotation marks
@@ -470,9 +463,16 @@
                        //       at whitespace
                        // but: +editor:("Robert V" "Mathias S") is already 
split correctly!
                        $sFqEditor = ( BsConfig::get( 
'MW::ExtendedSearch::ShowFacets' ) ) ? '{!tag=ed}' : '';
-                       $sFqEditor .= 'editor:("' . implode( '"' . $sOperator . 
'"', $this->aOptions['editor'] ) . '")';
+                       $sFqEditor .= 'editor:("' . implode( '"' . $sLogOp . 
'"', $this->aOptions['editor'] ) . '")';
                        $aFq[] = $sFqEditor;
                }
+
+               // Boost query
+               foreach ( $wgContentNamespaces as $iNs ) {
+                       $aBq[] = "namespace:{$iNs}^2";
+               }
+               // We want that files are also seen as a content namespace
+               $aBq[] = "namespace:999^2";
 
                $searchLimit = BsConfig::get( 
'MW::ExtendedSearch::LimitResults' );
 
@@ -482,13 +482,16 @@
                $this->aOptions['searchLimit'] = ( $searchLimit == 0 ) ? 15 : 
$searchLimit;
                $this->aOptions['titleExists'] = $this->titleExists( 
$this->oSearchRequest->sInput );
                $this->aOptions['format'] = $this->oSearchRequest->sFormat;
+               $this->aOptions['bExtendedForm'] = 
$this->oSearchRequest->bExtendedForm;
 
+               $this->aSearchOptions['defType'] = 'edismax';
                $this->aSearchOptions['fl'] = 
'uid,type,title,path,namespace,cat,ts,redirects,overall_type';
                $this->aSearchOptions['fq'] = $aFq;
                $this->aSearchOptions['sort'] = $this->aOptions['order'] . ' ' 
. $this->aOptions['asc'];
                $this->aSearchOptions['hl'] = 'on';
                $this->aSearchOptions['hl.fl'] = 'titleWord, titleReverse, 
sections, textWord, textReverse';
                $this->aSearchOptions['hl.snippets'] = BsConfig::get( 
'MW::ExtendedSearch::HighlightSnippets' );
+               $this->aSearchOptions['bq'] = implode( ' ', $aBq );
 
                if ( BsConfig::get( 'MW::ExtendedSearch::ShowFacets' ) ) {
                        $this->aSearchOptions['facet'] = 'on';
diff --git a/ExtendedSearch/includes/SolrPhpClient/Response.php 
b/ExtendedSearch/includes/SolrPhpClient/Response.php
index b60d66a..e624b12 100644
--- a/ExtendedSearch/includes/SolrPhpClient/Response.php
+++ b/ExtendedSearch/includes/SolrPhpClient/Response.php
@@ -1,35 +1,35 @@
 <?php
 /**
- * Copyright (c) 2007-2009, Conduit Internet Technologies, Inc. 
- * All rights reserved. 
- * 
- * Redistribution and use in source and binary forms, with or without 
- * modification, are permitted provided that the following conditions are met: 
- * 
- *  - Redistributions of source code must retain the above copyright notice, 
- *    this list of conditions and the following disclaimer. 
- *  - Redistributions in binary form must reproduce the above copyright 
- *    notice, this list of conditions and the following disclaimer in the 
- *    documentation and/or other materials provided with the distribution. 
- *  - Neither the name of Conduit Internet Technologies, Inc. nor the names of 
- *    its contributors may be used to endorse or promote products derived from 
- *    this software without specific prior written permission. 
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+ * Copyright (c) 2007-2009, Conduit Internet Technologies, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  - Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *  - Neither the name of Conduit Internet Technologies, Inc. nor the names of
+ *    its contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
- * 
+ *
  * @copyright Copyright 2007-2009 Conduit Internet Technologies, Inc. 
(http://conduit-it.com)
  * @license New BSD (http://solr-php-client.googlecode.com/svn/trunk/COPYING)
- * 
+ *
  * @package Apache
  * @subpackage Solr
  * @author Donovan Jimenez <[email protected]>
diff --git a/ExtendedSearch/includes/SolrPhpClient/Service.php 
b/ExtendedSearch/includes/SolrPhpClient/Service.php
index 1897955..a18a6c7 100644
--- a/ExtendedSearch/includes/SolrPhpClient/Service.php
+++ b/ExtendedSearch/includes/SolrPhpClient/Service.php
@@ -292,7 +292,10 @@
 
                if ($response->getHttpStatus() != 200)
                {
-                       throw new Exception('"' . $response->getHttpStatus() . 
'" Status: ' . $response->getHttpStatusMessage(), $response->getHttpStatus());
+                       throw new Exception(
+                               '"' . $response->getHttpStatus() .'" Status: ' 
. $response->getHttpStatusMessage() . ' URL: ' . urldecode( $url ),
+                               $response->getHttpStatus()
+                       );
                }
 
                return $response;

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9f7a8fd300d30372f3987af44e1904f238f3a978
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Smuggli <[email protected]>
Gerrit-Reviewer: Mglaser <[email protected]>
Gerrit-Reviewer: Pigpen <[email protected]>
Gerrit-Reviewer: Robert Vogel <[email protected]>
Gerrit-Reviewer: Smuggli <[email protected]>
Gerrit-Reviewer: Tweichart <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to