Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 5e85007

Browse files
committed
Fix up stuffs
1 parent a975159 commit 5e85007

File tree

5 files changed

+38
-43
lines changed

5 files changed

+38
-43
lines changed

assets/javascripts/discourse/connectors/full-page-search-below-search-header/semantic-search.gjs

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default class SemanticSearch extends Component {
3232
constructor() {
3333
super(...arguments);
3434
this.appEvents.on("full-page-search:trigger-search", this, this.onSearch);
35-
this.handleSearch();
35+
this.onSearch();
3636
}
3737

3838
willDestroy() {
@@ -42,10 +42,14 @@ export default class SemanticSearch extends Component {
4242

4343
@action
4444
onSearch() {
45-
if (!this.searching) {
46-
this.resetAiResults();
47-
return this.performHyDESearch();
45+
if (!this.searchEnabled) {
46+
return;
4847
}
48+
49+
this.initialSearchTerm = this.args.outletArgs.search;
50+
this.searching = true;
51+
this.resetAiResults();
52+
return this.performHyDESearch();
4953
}
5054

5155
get disableToggleSwitch() {
@@ -69,30 +73,28 @@ export default class SemanticSearch extends Component {
6973
);
7074
}
7175

72-
// Search results:
73-
if (this.AiResults.length > 0) {
74-
if (this.showingAiResults) {
75-
return I18n.t(
76-
"discourse_ai.embeddings.semantic_search_results.toggle",
77-
{
78-
count: this.AiResults.length,
79-
}
80-
);
81-
} else {
82-
return I18n.t(
83-
"discourse_ai.embeddings.semantic_search_results.toggle_hidden",
84-
{
85-
count: this.AiResults.length,
86-
}
87-
);
88-
}
89-
}
90-
9176
// Search loading:
9277
if (this.searching) {
9378
return I18n.t("discourse_ai.embeddings.semantic_search_loading");
9479
}
9580

81+
// We have results and we are showing them
82+
if (this.AiResults.length && this.showingAiResults) {
83+
return I18n.t("discourse_ai.embeddings.semantic_search_results.toggle", {
84+
count: this.AiResults.length,
85+
});
86+
}
87+
88+
// We have results but are hiding them
89+
if (this.AiResults.length && !this.showingAiResults) {
90+
return I18n.t(
91+
"discourse_ai.embeddings.semantic_search_results.toggle_hidden",
92+
{
93+
count: this.AiResults.length,
94+
}
95+
);
96+
}
97+
9698
// Typing to search:
9799
if (
98100
this.AiResults.length === 0 &&
@@ -140,18 +142,6 @@ export default class SemanticSearch extends Component {
140142
this.args.outletArgs.addSearchResults([], "topic_id");
141143
}
142144

143-
@action
144-
handleSearch() {
145-
if (!this.searchEnabled) {
146-
return;
147-
}
148-
149-
if (this.initialSearchTerm) {
150-
this.searching = true;
151-
return this.performHyDESearch();
152-
}
153-
}
154-
155145
performHyDESearch() {
156146
this.resetAiResults();
157147

@@ -182,7 +172,7 @@ export default class SemanticSearch extends Component {
182172
this.sortOrder = this.args.outletArgs.sortOrder;
183173

184174
if (this.validSearchOrder) {
185-
this.handleSearch();
175+
this.onSearch();
186176
} else {
187177
this.showingAiResults = false;
188178
this.resetAiResults();
@@ -195,7 +185,9 @@ export default class SemanticSearch extends Component {
195185
<div class="semantic-search__container search-results" role="region">
196186
<div class="semantic-search__results">
197187
<div
198-
class="semantic-search__searching {{if this.searching 'in-progress'}}"
188+
class="semantic-search__searching
189+
{{if this.searching 'in-progress'}}
190+
{{unless this.validSearchOrder 'unavailable'}}"
199191
>
200192
<DToggleSwitch
201193
disabled={{this.disableToggleSwitch}}
@@ -209,14 +201,15 @@ export default class SemanticSearch extends Component {
209201
{{this.searchStateText}}
210202
</div>
211203

212-
<AiIndicatorWave @loading={{this.searching}} />
204+
{{#if this.validSearchOrder}}
205+
<AiIndicatorWave @loading={{this.searching}} />
206+
{{/if}}
213207

214208
{{#unless this.validSearchOrder}}
215209

216210
<DTooltip
217211
@identifier="semantic-search-unavailable-tooltip"
218212
class="semantic-search__unavailable-tooltip"
219-
...attributes
220213
>
221214
<:trigger>
222215
{{icon "far-circle-question"}}

assets/stylesheets/modules/embeddings/common/semantic-search.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
display: flex;
1717
align-items: center;
1818

19-
&.in-progress {
19+
&.in-progress,
20+
&.unavailable {
2021
.semantic-search__searching-text {
2122
color: var(--primary-medium);
2223
}

config/locales/client.en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ en:
484484
none: "Sorry, our AI search found no matching topics"
485485
new: "Press 'search' to begin looking for new results with AI"
486486
unavailable: "AI results unavailable"
487-
semantic_search_unavailable_tooltip: "Search results must be sorted by Relevance to display AI results."
487+
semantic_search_unavailable_tooltip: "Search results must be sorted by Relevance to display AI results"
488488
ai_generated_result: "Search result found using AI"
489489
quick_search:
490490
suffix: "in all topics and posts with AI"

lib/embeddings/entry_point.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ module DiscourseAi
44
module Embeddings
55
class EntryPoint
66
def inject_into(plugin)
7+
# far-circle-question used by semantic search unavailable tooltip
8+
register_svg_icon "far-circle-question" if respond_to?(:register_svg_icon)
9+
710
# Include random topics in the suggested list *only* if there are no related topics.
811
plugin.register_modifier(
912
:topic_view_suggested_topics_options,

plugin.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343

4444
register_asset "stylesheets/modules/ai-bot/common/ai-artifact.scss"
4545

46-
register_svg_icon "far-circle-question" if respond_to?(:register_svg_icon)
47-
4846
module ::DiscourseAi
4947
PLUGIN_NAME = "discourse-ai"
5048

0 commit comments

Comments
 (0)