From 12c95f127e609a5fe1c50665e34121c80bba82f1 Mon Sep 17 00:00:00 2001 From: Adam Coffman Date: Tue, 20 Aug 2024 12:38:25 -0500 Subject: [PATCH] add a distinct clause when matching on aliases --- server/app/graphql/types/queries/typeahead_queries.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/app/graphql/types/queries/typeahead_queries.rb b/server/app/graphql/types/queries/typeahead_queries.rb index 0c4661dbd..c972266a0 100644 --- a/server/app/graphql/types/queries/typeahead_queries.rb +++ b/server/app/graphql/types/queries/typeahead_queries.rb @@ -42,7 +42,7 @@ def self.included(klass) description "Retrieve entity type typeahead fields for a entity mention search term." argument :query_term, GraphQL::Types::String, required: true end - + klass.field :acmg_codes_typeahead, [Types::Entities::AcmgCodeType], null: false do description "Retrieve ACMG Code options as a typeahead" argument :query_term, GraphQL::Types::String, required: true @@ -68,6 +68,7 @@ def variants_typeahead(query_term:, feature_id: nil) .where(deprecated: false) .where('variants.name ILIKE :query OR variant_aliases.name ILIKE :query', { query: "%#{query_term}%" }) .limit(20) + .distinct if feature_id scope.where(feature_id: feature_id) @@ -87,6 +88,7 @@ def disease_typeahead(query_term:) .where("disease_aliases.name ILIKE ?", "%#{query_term}%") .where.not(id: results.select('id')) .order("LENGTH(diseases.name) ASC") + .distinct .limit(10-results.size) return results + secondary_results else @@ -109,6 +111,7 @@ def therapy_typeahead(query_term:) .where("therapy_aliases.name ILIKE ?", "%#{query_term}%") .where.not(id: results.select('id') + secondary_results.select('id')) .order("LENGTH(therapies.name) ASC") + .distinct .limit(10-results.size) return results + secondary_results + tertiary_results @@ -136,6 +139,7 @@ def feature_typeahead(query_term:, feature_type: nil) .where("feature_aliases.name ILIKE ?", "#{query_term}%") .where.not(id: results.select('id')) .order("LENGTH(features.name) ASC") + .distinct .limit(10 - results.size) return (results + secondary_results).uniq else