diff --git a/app/models/concerns/searchable_model.rb b/app/models/concerns/searchable_model.rb index 7d38bdbc0..506080a76 100644 --- a/app/models/concerns/searchable_model.rb +++ b/app/models/concerns/searchable_model.rb @@ -37,13 +37,10 @@ module SearchableModel a_query = Regexp.escape(query) end - # quick fix to enable searching by repositoy_row id - id_index = { present: false } where_str = (attrs.map.with_index do |a, i| if a == 'repository_rows.id' - id_index = { present: true, val: i } - "(#{a}) = :t#{i} OR " + "CAST(#{a} AS TEXT) #{like} :t#{i} OR " else col = options[:at_search].to_s == 'true' ? "lower(#{a})": a "(trim_html_tags(#{col})) #{like} :t#{i} OR " @@ -52,11 +49,7 @@ module SearchableModel ).join[0..-5] vals = ( attrs.map.with_index do |_, i| - if id_index[:present] && id_index[:val] == i - ["t#{i}".to_sym, a_query.to_i] - else - ["t#{i}".to_sym, '\\y(' + a_query + ')\\y'] - end + ["t#{i}".to_sym, '\\y(' + a_query + ')\\y'] end ).to_h return where(where_str, vals) @@ -68,13 +61,10 @@ module SearchableModel if query.count(' ') > 0 unless attrs.empty? a_query = query.split.map { |a| "%#{sanitize_sql_like(a)}%" } - # quick fix to enable searching by repositoy_row id - id_index = { present: false } where_str = (attrs.map.with_index do |a, i| if a == 'repository_rows.id' - id_index = { present: true, val: i } - "(#{a}) IN (:t#{i}) OR " + "CAST(#{a} AS TEXT) #{like} ANY (array[:t#{i}]) OR " else "(trim_html_tags(#{a})) #{like} ANY (array[:t#{i}]) OR " end @@ -82,11 +72,7 @@ module SearchableModel ).join[0..-5] vals = ( attrs.map.with_index do |_, i| - if id_index[:present] && id_index[:val] == i - ["t#{i}".to_sym, a_query.map(&:to_i)] - else - ["t#{i}".to_sym, a_query] - end + ["t#{i}".to_sym, a_query] end ).to_h @@ -94,13 +80,10 @@ module SearchableModel end else unless attrs.empty? - # quick fix to enable searching by repositoy_row id - id_index = { present: false } where_str = (attrs.map.with_index do |a, i| if a == 'repository_rows.id' - id_index = { present: true, val: i } - "(#{a}) = :t#{i} OR " + "CAST(#{a} AS TEXT) #{like} :t#{i} OR " else "(trim_html_tags(#{a})) #{like} :t#{i} OR " end @@ -108,11 +91,7 @@ module SearchableModel ).join[0..-5] vals = ( attrs.map.with_index do |_, i| - if id_index[:present] && id_index[:val] == i - ["t#{i}".to_sym, sanitize_sql_like(query).to_i] - else - ["t#{i}".to_sym, "%#{sanitize_sql_like(query.to_s)}%"] - end + ["t#{i}".to_sym, "%#{sanitize_sql_like(query.to_s)}%"] end ).to_h