Skip to content

Commit

Permalink
feat(search): ✨ add experimental multi gateway search
Browse files Browse the repository at this point in the history
This is experiemental and just a proof of concept for further work.
For now, typing `\/ask` in the search query will trigger SMW Ask search
  • Loading branch information
alistair3149 committed Jul 7, 2023
1 parent c823ca4 commit 6adc0d7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions resources/skins.citizen.search/gateway/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
const gatewayConfig = require( '../config.json' ).wgCitizenSearchGateway;

/**
* Setup the gateway based on wiki configuration
* Setup the default gateway based on wiki configuration
*
* @return {module}
*/
function getGateway() {
function getDefaultGateway() {
switch ( gatewayConfig ) {
case 'mwActionApi':
return require( './mwActionApi.js' );
Expand All @@ -36,7 +36,23 @@ function getGateway() {
* @return {Object} Results
*/
async function getResults( searchQuery, controller ) {
const gateway = getGateway();
let gateway = getDefaultGateway();

/*
* Multi-gateway search experiment
* This is a rough proof of concept for allowing multiple search gateway
* We are using SMW Ask as an experiment
*
* TODO:
* - Clean up gateway into JSON data perhaps
* - Implement UI support (initial states, search syntax suggestions)
*/
const smwSearchCommand = '/ask ';

if ( searchQuery.startsWith( smwSearchCommand ) ) {
gateway = require( './smwAskApi.js' );
searchQuery = searchQuery.slice( smwSearchCommand.length );
}

const signal = controller.signal;

Expand Down

0 comments on commit 6adc0d7

Please sign in to comment.