mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 04:03:57 -06:00
FEATURE: Experimental API for custom full-page search types. (#20915)
This change adds an experimental API tagged as "Do not use", only intended to conduct a PoC to test semantic search in the AI plugin.
This commit is contained in:
parent
af98df8cb9
commit
ea4f7fb660
@ -37,6 +37,16 @@ export const SEARCH_TYPE_USERS = "users";
|
||||
|
||||
const PAGE_LIMIT = 10;
|
||||
|
||||
const customSearchTypes = [];
|
||||
|
||||
export function registerFullPageSearchType(
|
||||
translationKey,
|
||||
searchTypeId,
|
||||
searchFunc
|
||||
) {
|
||||
customSearchTypes.push({ translationKey, searchTypeId, searchFunc });
|
||||
}
|
||||
|
||||
export default Controller.extend({
|
||||
application: controller(),
|
||||
composer: controller(),
|
||||
@ -68,7 +78,7 @@ export default Controller.extend({
|
||||
init() {
|
||||
this._super(...arguments);
|
||||
|
||||
this.set("searchTypes", [
|
||||
const searchTypes = [
|
||||
{ name: I18n.t("search.type.default"), id: SEARCH_TYPE_DEFAULT },
|
||||
{
|
||||
name: this.siteSettings.tagging_enabled
|
||||
@ -77,7 +87,16 @@ export default Controller.extend({
|
||||
id: SEARCH_TYPE_CATS_TAGS,
|
||||
},
|
||||
{ name: I18n.t("search.type.users"), id: SEARCH_TYPE_USERS },
|
||||
]);
|
||||
];
|
||||
|
||||
customSearchTypes.forEach((type) => {
|
||||
searchTypes.push({
|
||||
name: I18n.t(type.translationKey),
|
||||
id: type.searchTypeId,
|
||||
});
|
||||
});
|
||||
|
||||
this.set("searchTypes", searchTypes);
|
||||
},
|
||||
|
||||
@discourseComputed("resultCount")
|
||||
@ -274,6 +293,13 @@ export default Controller.extend({
|
||||
return searchType === SEARCH_TYPE_DEFAULT;
|
||||
},
|
||||
|
||||
@discourseComputed("search_type")
|
||||
customSearchType(searchType) {
|
||||
return customSearchTypes.find(
|
||||
(type) => searchType === type["searchTypeId"]
|
||||
);
|
||||
},
|
||||
|
||||
@discourseComputed("bulkSelectEnabled")
|
||||
searchInfoClassNames(bulkSelectEnabled) {
|
||||
return bulkSelectEnabled
|
||||
@ -324,6 +350,12 @@ export default Controller.extend({
|
||||
|
||||
const searchKey = getSearchKey(args);
|
||||
|
||||
if (this.customSearchType) {
|
||||
const customSearch = this.customSearchType["searchFunc"];
|
||||
customSearch(this, args, searchKey);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (this.search_type) {
|
||||
case SEARCH_TYPE_CATS_TAGS:
|
||||
const categoryTagSearch = searchCategoryTag(
|
||||
|
@ -111,6 +111,7 @@ import { registerNotificationTypeRenderer } from "discourse/lib/notification-typ
|
||||
import { registerUserMenuTab } from "discourse/lib/user-menu/tab";
|
||||
import { registerModelTransformer } from "discourse/lib/model-transformers";
|
||||
import { registerCustomUserNavMessagesDropdownRow } from "discourse/controllers/user-private-messages";
|
||||
import { registerFullPageSearchType } from "discourse/controllers/full-page-search";
|
||||
|
||||
// If you add any methods to the API ensure you bump up the version number
|
||||
// based on Semantic Versioning 2.0.0. Please update the changelog at
|
||||
@ -2124,6 +2125,18 @@ class PluginApi {
|
||||
addUserMessagesNavigationDropdownRow(routeName, name, icon) {
|
||||
registerCustomUserNavMessagesDropdownRow(routeName, name, icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* EXPERIMENTAL. Do not use.
|
||||
* Adds a new search type which can be selected when visiting the full page search UI.
|
||||
*
|
||||
* @param {string} translationKey
|
||||
* @param {string} searchTypeId
|
||||
* @param {function} searchFunc - Available arguments: fullPage controller, search args, searchKey.
|
||||
*/
|
||||
addFullPageSearchType(translationKey, searchTypeId, searchFunc) {
|
||||
registerFullPageSearchType(translationKey, searchTypeId, searchFunc);
|
||||
}
|
||||
}
|
||||
|
||||
// from http://stackoverflow.com/questions/6832596/how-to-compare-software-version-number-using-js-only-number
|
||||
|
@ -150,7 +150,7 @@
|
||||
{{else}}
|
||||
<div class="search-results" role="region">
|
||||
<LoadMore @selector=".fps-result" @action={{action "loadMore"}}>
|
||||
{{#if this.usingDefaultSearchType}}
|
||||
{{#if (or this.usingDefaultSearchType this.customSearchType)}}
|
||||
<SearchResultEntries
|
||||
@posts={{this.model.posts}}
|
||||
@bulkSelectEnabled={{this.bulkSelectEnabled}}
|
||||
|
Loading…
Reference in New Issue
Block a user