mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-06-27 10:02:16 +00:00
FIX: Perform semantic search only when searchTerm is valid (#216)
This commit is contained in:
parent
6295b16678
commit
156931e1f4
@ -8,7 +8,11 @@ module DiscourseAi
|
|||||||
SEMANTIC_SEARCH_TYPE = "semantic_search"
|
SEMANTIC_SEARCH_TYPE = "semantic_search"
|
||||||
|
|
||||||
def 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 =
|
grouped_results =
|
||||||
Search::GroupedSearchResults.new(
|
Search::GroupedSearchResults.new(
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
<div
|
<div
|
||||||
class="semantic-search__results"
|
class="semantic-search__results"
|
||||||
{{did-insert this.setup}}
|
{{did-insert this.setup}}
|
||||||
{{did-insert this.debouncedSearch}}
|
|
||||||
{{will-destroy this.teardown}}
|
{{will-destroy this.teardown}}
|
||||||
>
|
>
|
||||||
{{#if this.searching}}
|
{{#if this.searching}}
|
||||||
|
@ -3,7 +3,7 @@ import { action, computed } from "@ember/object";
|
|||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import { tracked } from "@glimmer/tracking";
|
import { tracked } from "@glimmer/tracking";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
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 discourseDebounce from "discourse-common/lib/debounce";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
import { bind } from "discourse-common/utils/decorators";
|
import { bind } from "discourse-common/utils/decorators";
|
||||||
@ -15,6 +15,7 @@ export default class extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@service appEvents;
|
@service appEvents;
|
||||||
|
@service siteSettings;
|
||||||
|
|
||||||
@tracked searching = true;
|
@tracked searching = true;
|
||||||
@tracked collapsedResults = true;
|
@tracked collapsedResults = true;
|
||||||
@ -25,9 +26,12 @@ export default class extends Component {
|
|||||||
return this.args.outletArgs.search;
|
return this.args.outletArgs.search;
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed("args.outletArgs.type")
|
@computed("args.outletArgs.type", "searchTerm")
|
||||||
get searchEnabled() {
|
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")
|
@computed("results")
|
||||||
@ -57,7 +61,7 @@ export default class extends Component {
|
|||||||
|
|
||||||
@bind
|
@bind
|
||||||
performHyDESearch() {
|
performHyDESearch() {
|
||||||
if (!this.searchTerm || !this.searchEnabled) {
|
if (!this.searchEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user