From f43442404d37cfb04b012c73c24b1dc4bf01168d Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 26 Feb 2018 14:27:22 +0100 Subject: AutocompleteLinesController: Include company name in filter The `#display_name` used in the drop-down on `ReferentialVehicleJourneys#index` includes the line's company name. Include this as a field to filter lines by. Additionally, use `%query%` filtering everywhere. It's going to be slower, but will produce the same behaviour for all fields for consistency and is easier for searching by company name when you might want to filter by a term in the middle of the name. Refs #5889 --- app/controllers/autocomplete_lines_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'app/controllers/autocomplete_lines_controller.rb') diff --git a/app/controllers/autocomplete_lines_controller.rb b/app/controllers/autocomplete_lines_controller.rb index 945736ab9..0202ea054 100644 --- a/app/controllers/autocomplete_lines_controller.rb +++ b/app/controllers/autocomplete_lines_controller.rb @@ -9,13 +9,15 @@ class AutocompleteLinesController < ChouetteController @lines = referential.line_referential.lines filter = <<~SQL - number LIKE ? - OR name LIKE ? + lines.number LIKE ? + OR lines.name LIKE ? + OR companies.name ILIKE ? SQL @lines = @lines + .joins(:company) .where( filter, - *Array.new(2, "#{params[:q]}%") + *Array.new(3, "%#{params[:q]}%") ) .search(params[:q]) .result -- cgit v1.2.3