From 00615b2b6b7a63a8ddec16778881aeba327221a8 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 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/companies/helper.ex b/lib/companies/helper.ex index b7bbbaf4..daf1a948 100644 --- a/lib/companies/helper.ex +++ b/lib/companies/helper.ex @@ -5,8 +5,18 @@ 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 + list + |> Enum.filter( + &(String.contains?(String.downcase(&1.name), String.downcase(search_param)) or + String.contains?(String.downcase(&1.industry), String.downcase(search_param))) + ) + else + list + end end def sorted_list(list, params) do