From 401bbed67b8dfcd3d921119c8e41836e982f06fe Mon Sep 17 00:00:00 2001 From: Jim Date: Wed, 28 Feb 2024 10:42:19 +0000 Subject: [PATCH] Improve service filtering (#19811) * Improve service filtering Split filter term by space and match if each word is individually present * Prettier formatting * Fix un-necessary toLowerCase() call Co-authored-by: karwosts <32912880+karwosts@users.noreply.github.com> * Combine filter check conditions into the same loop * Prettier formatting --------- Co-authored-by: karwosts <32912880+karwosts@users.noreply.github.com> --- src/components/ha-service-picker.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/ha-service-picker.ts b/src/components/ha-service-picker.ts index c370928521e1..c27c039a8e96 100644 --- a/src/components/ha-service-picker.ts +++ b/src/components/ha-service-picker.ts @@ -114,11 +114,14 @@ class HaServicePicker extends LitElement { if (!filter) { return processedServices; } - return processedServices.filter( - (service) => - service.service.toLowerCase().includes(filter) || - service.name?.toLowerCase().includes(filter) - ); + const split_filter = filter.split(" "); + return processedServices.filter((service) => { + const lower_service_name = service.name.toLowerCase(); + const lower_service = service.service.toLowerCase(); + return split_filter.every( + (f) => lower_service_name.includes(f) || lower_service.includes(f) + ); + }); } );