Robert Vogel has submitted this change and it was merged.

Change subject: Phase 2: Querying and UI started
......................................................................


Phase 2: Querying and UI started

Change-Id: I4d7761c6a8cf16f1873a4705410b4cfe4872bd82
---
M extension.json
M i18n/en.json
A i18n/qqq.json
D resouces/ext.blueSpiceExtendedSearch.SearchCenter.js
A resources/ext.blueSpiceExtendedSearch.SearchCenter.js
M src/Backend.php
M src/MediaWiki/Api/Query.php
M src/MediaWiki/Specials/SearchCenter.php
A src/Source/Formatter/Base.php
M src/Source/Job/UpdateBase.php
A src/Source/QueryProcessor/Base.php
11 files changed, 155 insertions(+), 11 deletions(-)

Approvals:
  Robert Vogel: Verified; Looks good to me, approved



diff --git a/extension.json b/extension.json
index a8d1a38..c9fd3f3 100644
--- a/extension.json
+++ b/extension.json
@@ -31,6 +31,20 @@
        "APIModules": {
                "bs-extendedsearch-query": 
"BS\\ExtendedSearch\\MediaWiki\\Api\\Query"
        },
+       "ResourceFileModulePaths": {
+               "localBasePath": "resources",
+               "remoteExtPath": "BlueSpiceExtendedSearch/resources"
+       },
+       "ResourceModules": {
+               "ext.blueSpiceExtendedSearch.SearchCenter": {
+                       "scripts": [
+                               "ext.blueSpiceExtendedSearch.SearchCenter.js"
+                       ],
+                       "dependencies" : [
+                               "oojs-ui-core"
+                       ]
+               }
+       },
        "config": {
                "_prefix": "bsgES",
                "Backends": {
diff --git a/i18n/en.json b/i18n/en.json
index 2e5ed19..b053e75 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -1,7 +1,13 @@
 {
        "@metadata": {
-               "authors": []
+               "authors": [
+                       "Robert Vogel <vo...@hallowelt.com>"
+               ]
        },
        "extensionname-bsextendedsearch": "BlueSpice ExtendedSearch",
-       "bs-extendedsearch-desc": "Elasticsearch search backend"
+       "bs-extendedsearch-desc": "Elasticsearch search backend",
+       "bssearchcenter": "Search center",
+       "apihelp-bs-extendedsearch-query-description": "Search the index",
+       "apihelp-bs-extendedsearch-query-param-q": "The query term",
+       "bs-extendedsearch-search-input-placeholder": "Find ..."
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
new file mode 100644
index 0000000..dac68b9
--- /dev/null
+++ b/i18n/qqq.json
@@ -0,0 +1,13 @@
+{
+       "@metadata": {
+               "authors": [
+                       "Robert Vogel <vo...@hallowelt.com>"
+               ]
+       },
+       "extensionname-bsextendedsearch": "Used in 
[{{canonicalurl:Special:Version}} Special:Version], description of extended 
search extension.",
+       "bs-extendedsearch-desc": "Used in [{{canonicalurl:Special:Version}} 
Special:Version], description of extended search extension.",
+       "bssearchcenter": "Special page name for extended search",
+       "apihelp-bs-extendedsearch-query-description": "Describes the API 
endpoint that querys the search index",
+       "apihelp-bs-extendedsearch-query-param-q": "Describes parameter that 
holds the query term",
+       "bs-extendedsearch-search-input-placeholder": "Placeholder text within 
the search input field"
+}
diff --git a/resouces/ext.blueSpiceExtendedSearch.SearchCenter.js 
b/resouces/ext.blueSpiceExtendedSearch.SearchCenter.js
deleted file mode 100644
index 415aae4..0000000
--- a/resouces/ext.blueSpiceExtendedSearch.SearchCenter.js
+++ /dev/null
@@ -1,3 +0,0 @@
-(function( mw, $, d, undefined ){
-       
-})( mediaWiki, jQuery, document );
\ No newline at end of file
diff --git a/resources/ext.blueSpiceExtendedSearch.SearchCenter.js 
b/resources/ext.blueSpiceExtendedSearch.SearchCenter.js
new file mode 100644
index 0000000..bee0643
--- /dev/null
+++ b/resources/ext.blueSpiceExtendedSearch.SearchCenter.js
@@ -0,0 +1,22 @@
+(function( mw, $, d, undefined ){
+       var searchButton = OO.ui.infuse( 'bs-es-btn-search' );
+       searchButton.on( 'click', function () {
+               //Do something
+       });
+
+       var searchButton = OO.ui.infuse( 'bs-es-tf-search' );
+       var api = new mw.Api();
+       searchButton.on( 'change', function ( value ) {
+               searchButton.popPending();
+               searchButton.pushPending();
+
+               api.abort();
+               api.get({
+                       'action': 'bs-extendedsearch-query',
+                       'q': value
+               })
+               .done( function() {
+                       searchButton.popPending();
+               });
+       });
+})( mediaWiki, jQuery, document );
\ No newline at end of file
diff --git a/src/Backend.php b/src/Backend.php
index be11bd0..275f868 100644
--- a/src/Backend.php
+++ b/src/Backend.php
@@ -75,6 +75,10 @@
                return $this->aSources;
        }
 
+       /**
+        *
+        * @return \Elastica\Client
+        */
        public function getClient() {
                if( $this->oClient === null ) {
                        $this->oClient = new \Elastica\Client(
@@ -86,6 +90,37 @@
        }
 
        /**
+        *
+        * @param string $sTerm
+        * @param \User $oUser
+        * @param array $aParams
+        * @return \Elastica\ResultSet
+        */
+       public function search( $sTerm, $oUser, $aParams = [] ) {
+               $oSearch = new \Elastica\Search( $this->getClient() );
+               $oQueryBuilder = new \Elastica\QueryBuilder();
+               $oQuery = new \Elastica\Query();
+               $oQuery->setQuery(
+                       $oQueryBuilder->query()->query_string( $sTerm )
+               );
+
+               $oSearch->setQuery( $oQuery );
+               //TODO: Apply all QueryProcessors/Modifiers
+
+               return $oSearch->search();
+       }
+
+       /**
+        *
+        * @param \Elastica\Result[] $aResults
+        * @return stdClass[]
+        */
+       public function formatResults( $aResults ) {
+               
+               return [];
+       }
+
+       /**
         * @return
         */
        public function getIndexManagers() {
diff --git a/src/MediaWiki/Api/Query.php b/src/MediaWiki/Api/Query.php
index bba6c36..1b42a7a 100644
--- a/src/MediaWiki/Api/Query.php
+++ b/src/MediaWiki/Api/Query.php
@@ -2,8 +2,28 @@
 
 namespace BS\ExtendedSearch\MediaWiki\Api;
 
-class Query extends \ApiQueryBase {
+class Query extends \ApiBase {
        public function execute() {
+               $oResult = $this->getResult();
+               $sQuery = $this->getParameter( 'q' );
 
+               $oBackend = \BS\ExtendedSearch\Backend::instance( 'local' ); 
//TODO: Use parameter for selection of "backend" and "source"
+               $oResultSet = $oBackend->search( $sQuery, $this->getUser() );
+
+               $oResult->addValue( null , 'results', $oBackend->formatResults( 
$oResultSet->getResults() ) );
+               $oResult->addValue( null , 'total', $oResultSet->getTotalHits() 
);
+               //Future:
+               //$oResult->addValue( null , 'aggregations', 
$oResultSet->getAggregations() );
+               //$oResult->addValue( null , 'suggests', 
$oResultSet->getSuggests() );
+       }
+
+       protected function getAllowedParams() {
+               return [
+                       'q' => [
+                               \ApiBase::PARAM_TYPE => 'string',
+                               \ApiBase::PARAM_REQUIRED => true,
+                               \ApiBase::PARAM_HELP_MSG => 
'apihelp-bs-extendedsearch-query-param-q',
+                       ]
+               ];
        }
 }
\ No newline at end of file
diff --git a/src/MediaWiki/Specials/SearchCenter.php 
b/src/MediaWiki/Specials/SearchCenter.php
index 1b87b31..df870fd 100644
--- a/src/MediaWiki/Specials/SearchCenter.php
+++ b/src/MediaWiki/Specials/SearchCenter.php
@@ -3,14 +3,33 @@
 namespace BS\ExtendedSearch\MediaWiki\Specials;
 
 class SearchCenter extends \SpecialPage {
-       public function __construct($name = '', $restriction = '', $listed = 
true, $function = false, $file = '', $includable = false) {
+       public function __construct( $name = '', $restriction = '', $listed = 
true, $function = false, $file = '', $includable = false ) {
                parent::__construct( 'BSSearchCenter' );
        }
 
        public function execute( $subPage ) {
-               $oSearchField = new \OOUI\TextInputWidget();
+               $this->setHeaders();
 
-               $this->getOutput()->enableOOUI();
-               $this->getOutput()->addHTML( $oSearchField );
+               $out = $this->getOutput();
+               $out->addModules( "ext.blueSpiceExtendedSearch.SearchCenter" );
+
+               $oSearchField = new \OOUI\TextInputWidget([
+                       'placeholder' => wfMessage( 
'bs-extendedsearch-search-input-placeholder' )->plain(),
+                       'id' => 'bs-es-tf-search',
+                       'infusable' => true
+               ]);
+               $oButton = new \OOUI\ButtonWidget([
+                       'id' => 'bs-es-btn-search',
+                       'icon' => 'search',
+                       'infusable' => true
+               ]);
+               $oFieldLayout = new \OOUI\ActionFieldLayout( $oSearchField, 
$oButton );
+
+               $out->enableOOUI();
+               $out->addHTML( $oFieldLayout );
+       }
+
+       protected function getGroupName() {
+               return 'bluespice';
        }
 }
\ No newline at end of file
diff --git a/src/Source/Formatter/Base.php b/src/Source/Formatter/Base.php
new file mode 100644
index 0000000..64b4855
--- /dev/null
+++ b/src/Source/Formatter/Base.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace BS\ExtendedSearch\Source\Formatter;
+
+class Base {
+       public function format( $aItem ) {
+               
+       }
+}
\ No newline at end of file
diff --git a/src/Source/Job/UpdateBase.php b/src/Source/Job/UpdateBase.php
index 6c72130..a9baf52 100644
--- a/src/Source/Job/UpdateBase.php
+++ b/src/Source/Job/UpdateBase.php
@@ -12,7 +12,7 @@
         * @return \BS\ExtendedSearch\Backend
         */
        protected function getBackend() {
-               return \BS\ExtendedSearch\Backend::factory( $this->sBackendKey 
);
+               return \BS\ExtendedSearch\Backend::instance( $this->sBackendKey 
);
        }
 
        protected function getSource() {
diff --git a/src/Source/QueryProcessor/Base.php 
b/src/Source/QueryProcessor/Base.php
new file mode 100644
index 0000000..a7ed1e3
--- /dev/null
+++ b/src/Source/QueryProcessor/Base.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace BS\ExtendedSearch\Source\QueryProcessor;
+
+class Base {
+       public function process( $query, $oUser ) {
+
+       }
+}
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4d7761c6a8cf16f1873a4705410b4cfe4872bd82
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtendedSearch
Gerrit-Branch: master
Gerrit-Owner: Robert Vogel <vo...@hallowelt.biz>
Gerrit-Reviewer: Robert Vogel <vo...@hallowelt.biz>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>

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

Reply via email to