Skip to content

Commit

Permalink
add a distinct clause when matching on aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
acoffman committed Aug 20, 2024
1 parent e3bd1ba commit 12c95f1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/app/graphql/types/queries/typeahead_queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 12c95f1

Please sign in to comment.