From b3575825d4dd0990464d5365ec78a588ce5d13e9 Mon Sep 17 00:00:00 2001 From: Ahmed Ismail Date: Tue, 7 Nov 2023 23:40:00 +0500 Subject: [PATCH] Fix search by company name and search by industry name --- lib/companies/helper.ex | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/companies/helper.ex b/lib/companies/helper.ex index b7bbbaf4..1e53d235 100644 --- a/lib/companies/helper.ex +++ b/lib/companies/helper.ex @@ -5,8 +5,17 @@ defmodule Companies.Helpers do @default_page_size "16" - def searched_list(list, _params) do - list + def searched_list(list, params) do + search_param = params["search"]["text"] + + if search_param do + Enum.filter(list, fn %{name: name, industry: industry} -> + String.contains?(String.downcase(name), String.downcase(search_param)) or + String.contains?(String.downcase(industry), String.downcase(search_param)) + end) + else + list + end end def sorted_list(list, params) do