dgidb / dgidb-v5

Providing interactions between drugs and genes sourced from a variety of publications and knowledgebases
https://dgidb.org
MIT License
14 stars 2 forks source link

Use case insensitive, left anchored matching for drug names #478

Closed acoffman closed 6 months ago

acoffman commented 6 months ago

closes #476

The previous version was using IN and passing an array which will exact match. Unfortunately, as far as I'm aware, there is no equivalent ILIKE IN so we need to build the query up manually.

Array.new(size, value) initializes a new array of strings with the value 'name ILIKE ?' equivalent to the number of drug names passed in.

value.map {|v| "#{v}%"} tacks on the % for left anchored wildcard matching to each search term, and then the * splats those terms out into parameters to the where clause. So you end up with something that will look like

scope.where("name ILIKE ? OR name ILIKE ?", 'foo', 'bar'). This allows us to dynamically build the query while still using ActiveRecord's built in query parameterization/escaping.