FIX: Perform semantic search only when searchTerm is valid (#216)

This commit is contained in:
Roman Rizzi 2023-09-11 11:32:05 -03:00 committed by GitHub
parent 6295b16678
commit 156931e1f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 6 deletions

View File

@ -8,7 +8,11 @@ module DiscourseAi
SEMANTIC_SEARCH_TYPE = "semantic_search"
def search
query = params[:q]
query = params[:q].to_s
if query.length < SiteSetting.min_search_term_length
raise Discourse::InvalidParameters.new(:q)
end
grouped_results =
Search::GroupedSearchResults.new(

View File

@ -3,7 +3,6 @@
<div
class="semantic-search__results"
{{did-insert this.setup}}
{{did-insert this.debouncedSearch}}
{{will-destroy this.teardown}}
>
{{#if this.searching}}

View File

@ -3,7 +3,7 @@ import { action, computed } from "@ember/object";
import I18n from "I18n";
import { tracked } from "@glimmer/tracking";
import { ajax } from "discourse/lib/ajax";
import { translateResults } from "discourse/lib/search";
import { isValidSearchTerm, translateResults } from "discourse/lib/search";
import discourseDebounce from "discourse-common/lib/debounce";
import { inject as service } from "@ember/service";
import { bind } from "discourse-common/utils/decorators";
@ -15,6 +15,7 @@ export default class extends Component {
}
@service appEvents;
@service siteSettings;
@tracked searching = true;
@tracked collapsedResults = true;
@ -25,9 +26,12 @@ export default class extends Component {
return this.args.outletArgs.search;
}
@computed("args.outletArgs.type")
@computed("args.outletArgs.type", "searchTerm")
get searchEnabled() {
return this.args.outletArgs.type === SEARCH_TYPE_DEFAULT;
return (
this.args.outletArgs.type === SEARCH_TYPE_DEFAULT &&
isValidSearchTerm(this.searchTerm, this.siteSettings)
);
}
@computed("results")
@ -57,7 +61,7 @@ export default class extends Component {
@bind
performHyDESearch() {
if (!this.searchTerm || !this.searchEnabled) {
if (!this.searchEnabled) {
return;
}