Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4095837
SearchProvider.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
SearchProvider.js
View Options
const
{
CommandPaletteItem
,
CommandPaletteProvider
,
CommandPaletteActionResult
}
=
require
(
'../types.js'
);
const
SearchClientFactory
=
require
(
'../searchClients/SearchClientFactory.js'
);
const
{
getNavigationAction
}
=
require
(
'../utils/providerActions.js'
);
/** @type {CommandPaletteProvider} */
module
.
exports
=
{
id
:
'search'
,
isAsync
:
true
,
debounceMs
:
250
,
keepStaleResultsOnQueryChange
:
true
,
/**
* Determines if this provider should handle the current query.
*
* @param {string} query The search query.
* @return {boolean}
*/
canProvide
(
query
)
{
// Handles non-empty queries that are not slash commands
return
!!
query
&&
!
query
.
startsWith
(
'/'
);
},
/**
* Performs the search using the configured SearchClient and returns results.
*
* @param {string} query The search query.
* @return {Promise<Array<CommandPaletteItem>>} A promise resolving to search results.
*/
async
getResults
(
query
)
{
const
searchClient
=
SearchClientFactory
.
create
();
try
{
const
{
fetch
}
=
searchClient
.
fetchByQuery
(
query
);
const
searchResponse
=
await
fetch
;
const
results
=
searchResponse
.
results
??
[];
// Ensure source is added by the provider
return
Array
.
isArray
(
results
)
?
results
.
map
(
(
item
)
=>
(
{
...
item
,
source
:
this
.
id
}
)
)
:
[];
}
catch
(
error
)
{
if
(
error
.
name
===
'AbortError'
)
{
// Search was aborted, ignore
return
[];
}
throw
error
;
}
},
/**
* Handles the selection of a search result item.
*
* @param {CommandPaletteItem} item The selected item.
* @return {Promise<CommandPaletteActionResult>} Action result.
*/
async
onResultSelect
(
item
)
{
return
getNavigationAction
(
item
);
}
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Aug 18, 14:05 (4 w, 4 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
31/1e/3fdcb1452bd7b3da76870cfc5d15
Default Alt Text
SearchProvider.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment