Skip to content

Commit

Permalink
rank typeahead results by length of matched name
Browse files Browse the repository at this point in the history
  • Loading branch information
acoffman committed Jan 28, 2025
1 parent f7beda9 commit 4ed58e9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions server/app/graphql/types/queries/typeahead_queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ def disease_typeahead(query_term:)
base_query = Disease.where(deprecated: false)
results = base_query.where("diseases.name ILIKE ?", "%#{query_term}%")
.or(base_query.where("diseases.doid ILIKE ?", "#{query_term}%"))
#.order("LENGTH(diseases.name) ASC")
.order("LENGTH(diseases.name) ASC")
.limit(10)
if results.size < 10
secondary_results = base_query.eager_load(:disease_aliases)
.where("disease_aliases.name ILIKE ?", "%#{query_term}%")
.where.not(id: results.select('id'))
#.order("LENGTH(diseases.name) ASC")
.order("LENGTH(diseases.name) ASC")
.distinct
.limit(10-results.size)
return results + secondary_results
Expand All @@ -100,7 +100,7 @@ def therapy_typeahead(query_term:)
base_query = Therapy.where(deprecated: false)
results = base_query.where("therapies.name ILIKE ?", "#{query_term}%")
.or(base_query.where("therapies.ncit_id ILIKE ?", "%#{query_term}%"))
#.order("LENGTH(therapies.name) ASC")
.order("LENGTH(therapies.name) ASC")
.limit(10)
if results.size < 10
secondary_results = base_query.where('therapies.name ILIKE ?', "%#{query_term}%")
Expand All @@ -110,7 +110,7 @@ def therapy_typeahead(query_term:)
tertiary_results = base_query.eager_load(:therapy_aliases)
.where("therapy_aliases.name ILIKE ?", "%#{query_term}%")
.where.not(id: results.select('id') + secondary_results.select('id'))
#.order("LENGTH(therapies.name) ASC")
.order("LENGTH(therapies.name) ASC")
.distinct
.limit(10-results.size)

Expand All @@ -131,14 +131,14 @@ def feature_typeahead(query_term:, feature_type: nil)
end

results = base_query.where('features.name ILIKE ?', "#{query_term}%")
#.order("LENGTH(features.name) ASC")
.order("LENGTH(features.name) ASC")
.limit(10)

if results.size < 10
secondary_results = base_query.eager_load(:feature_aliases)
.where("feature_aliases.name ILIKE ?", "#{query_term}%")
.where.not(id: results.select('id'))
#.order("LENGTH(features.name) ASC")
.order("LENGTH(features.name) ASC")
.distinct
.limit(10 - results.size)
return (results + secondary_results).uniq
Expand Down

0 comments on commit 4ed58e9

Please sign in to comment.