DEV: Move semantic search from connector to component (#1048)

This commit is contained in:
Mark VanLandingham 2025-01-02 12:32:49 -06:00 committed by GitHub
parent 11d0f60f1e
commit b6cefd10fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 18 deletions

View File

@ -11,13 +11,9 @@ import { isValidSearchTerm, translateResults } from "discourse/lib/search";
import icon from "discourse-common/helpers/d-icon"; import icon from "discourse-common/helpers/d-icon";
import I18n, { i18n } from "discourse-i18n"; import I18n, { i18n } from "discourse-i18n";
import DTooltip from "float-kit/components/d-tooltip"; import DTooltip from "float-kit/components/d-tooltip";
import AiIndicatorWave from "../../components/ai-indicator-wave"; import AiIndicatorWave from "./ai-indicator-wave";
export default class SemanticSearch extends Component {
static shouldRender(_args, { siteSettings }) {
return siteSettings.ai_embeddings_semantic_search_enabled;
}
export default class AiFullPageSearch extends Component {
@service appEvents; @service appEvents;
@service router; @service router;
@service siteSettings; @service siteSettings;
@ -26,8 +22,8 @@ export default class SemanticSearch extends Component {
@tracked searching; @tracked searching;
@tracked AiResults = []; @tracked AiResults = [];
@tracked showingAiResults = false; @tracked showingAiResults = false;
@tracked sortOrder = this.args.outletArgs.sortOrder; @tracked sortOrder = this.args.sortOrder;
initialSearchTerm = this.args.outletArgs.search; initialSearchTerm = this.args.searchTerm;
constructor() { constructor() {
super(...arguments); super(...arguments);
@ -46,7 +42,7 @@ export default class SemanticSearch extends Component {
return; return;
} }
this.initialSearchTerm = this.args.outletArgs.search; this.initialSearchTerm = this.args.searchTerm;
this.searching = true; this.searching = true;
this.resetAiResults(); this.resetAiResults();
return this.performHyDESearch(); return this.performHyDESearch();
@ -110,16 +106,16 @@ export default class SemanticSearch extends Component {
} }
get searchTerm() { get searchTerm() {
if (this.initialSearchTerm !== this.args.outletArgs.search) { if (this.initialSearchTerm !== this.args.searchTerm) {
this.initialSearchTerm = undefined; this.initialSearchTerm = undefined;
} }
return this.args.outletArgs.search; return this.args.searchTerm;
} }
get searchEnabled() { get searchEnabled() {
return ( return (
this.args.outletArgs.type === SEARCH_TYPE_DEFAULT && this.args.searchType === SEARCH_TYPE_DEFAULT &&
isValidSearchTerm(this.searchTerm, this.siteSettings) && isValidSearchTerm(this.searchTerm, this.siteSettings) &&
this.validSearchOrder this.validSearchOrder
); );
@ -128,9 +124,9 @@ export default class SemanticSearch extends Component {
@action @action
toggleAiResults() { toggleAiResults() {
if (this.showingAiResults) { if (this.showingAiResults) {
this.args.outletArgs.addSearchResults([], "topic_id"); this.args.addSearchResults([], "topic_id");
} else { } else {
this.args.outletArgs.addSearchResults(this.AiResults, "topic_id"); this.args.addSearchResults(this.AiResults, "topic_id");
} }
this.showingAiResults = !this.showingAiResults; this.showingAiResults = !this.showingAiResults;
} }
@ -139,7 +135,7 @@ export default class SemanticSearch extends Component {
resetAiResults() { resetAiResults() {
this.AiResults = []; this.AiResults = [];
this.showingAiResults = false; this.showingAiResults = false;
this.args.outletArgs.addSearchResults([], "topic_id"); this.args.addSearchResults([], "topic_id");
} }
performHyDESearch() { performHyDESearch() {
@ -168,8 +164,8 @@ export default class SemanticSearch extends Component {
@action @action
sortChanged() { sortChanged() {
if (this.sortOrder !== this.args.outletArgs.sortOrder) { if (this.sortOrder !== this.args.sortOrder) {
this.sortOrder = this.args.outletArgs.sortOrder; this.sortOrder = this.args.sortOrder;
if (this.validSearchOrder) { if (this.validSearchOrder) {
this.onSearch(); this.onSearch();
@ -181,7 +177,7 @@ export default class SemanticSearch extends Component {
} }
<template> <template>
<span {{didUpdate this.sortChanged @outletArgs.sortOrder}}></span> <span {{didUpdate this.sortChanged @sortOrder}}></span>
<div class="semantic-search__container search-results" role="region"> <div class="semantic-search__container search-results" role="region">
<div class="semantic-search__results"> <div class="semantic-search__results">
<div <div

View File

@ -0,0 +1,17 @@
import Component from "@glimmer/component";
import AiSemanticSearch from "../../components/ai-full-page-search";
export default class AiFullPageSearchConnector extends Component {
static shouldRender(_args, { siteSettings }) {
return siteSettings.ai_embeddings_semantic_search_enabled;
}
<template>
<AiSemanticSearch
@sortOrder={{@outletArgs.sortOrder}}
@searchTerm={{@outletArgs.search}}
@searchType={{@outletArgs.type}}
@addSearchResults={{@outletArgs.addSearchResults}}
/>
</template>
}