From 1463a967f69e681055bd07e99cbb327c6c7f7d6f Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Wed, 7 Dec 2022 18:59:46 -0600 Subject: [PATCH] Implement case insensitive search in the samples index (#1518) Closes #1517 --- web/samples_index/lib/src/samples.yaml | 4 ++-- web/samples_index/lib/src/search.dart | 7 +++++-- web/samples_index/test/samples_index_test.dart | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/web/samples_index/lib/src/samples.yaml b/web/samples_index/lib/src/samples.yaml index 751a150df..96ce47ff4 100644 --- a/web/samples_index/lib/src/samples.yaml +++ b/web/samples_index/lib/src/samples.yaml @@ -11,7 +11,7 @@ samples: - url: images/gallery4.png alt: Crane app screenshot - url: images/gallery5.png - alt: Shrine app screnshot + alt: Shrine app screenshot source: https://github.com/flutter/gallery web: https://gallery.flutter.dev description: > @@ -416,7 +416,7 @@ samples: - url: images/web_dashboard1.png alt: Web Dashboard screenshot - url: images/web_dashboard2.png - alt: Web Dashbaord screenshot + alt: Web Dashboard screenshot - url: images/web_dashboard3.png alt: Web Dashboard screenshot source: https://github.com/flutter/samples/tree/main/experimental/web_dashboard diff --git a/web/samples_index/lib/src/search.dart b/web/samples_index/lib/src/search.dart index eb9b06c55..c8d00c510 100644 --- a/web/samples_index/lib/src/search.dart +++ b/web/samples_index/lib/src/search.dart @@ -6,8 +6,11 @@ bool matchesQuery(String query, String sampleAttributes) { if (query.isEmpty) { return true; } - var queryWords = query.split(' ')..removeWhere((s) => s.isEmpty); - var attributes = sampleAttributes.split(' ')..removeWhere((s) => s.isEmpty); + + var queryWords = query.toLowerCase().split(' ') + ..removeWhere((s) => s.isEmpty); + var attributes = sampleAttributes.toLowerCase().split(' ') + ..removeWhere((s) => s.isEmpty); // Test for type filter // This will check whether a type parameter is present in the diff --git a/web/samples_index/test/samples_index_test.dart b/web/samples_index/test/samples_index_test.dart index bee079409..97ee6f10c 100644 --- a/web/samples_index/test/samples_index_test.dart +++ b/web/samples_index/test/samples_index_test.dart @@ -107,7 +107,9 @@ void main() { // Test if various queries match these attributes expect(matchesQuery('foo', attributes), false); + expect(matchesQuery('Foo', attributes), false); expect(matchesQuery('kittens', attributes), true); + expect(matchesQuery('Kittens', attributes), true); expect(matchesQuery('tag:cats', attributes), true); expect(matchesQuery('tag:dogs', attributes), false); expect(matchesQuery('package:path', attributes), true);