1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 22:38:42 +00:00

Implement case insensitive search in the samples index (#1518)

Closes #1517
This commit is contained in:
Parker Lougheed
2022-12-07 18:59:46 -06:00
committed by GitHub
parent ea1ad9d043
commit 1463a967f6
3 changed files with 9 additions and 4 deletions

View File

@@ -11,7 +11,7 @@ samples:
- url: images/gallery4.png - url: images/gallery4.png
alt: Crane app screenshot alt: Crane app screenshot
- url: images/gallery5.png - url: images/gallery5.png
alt: Shrine app screnshot alt: Shrine app screenshot
source: https://github.com/flutter/gallery source: https://github.com/flutter/gallery
web: https://gallery.flutter.dev web: https://gallery.flutter.dev
description: > description: >
@@ -416,7 +416,7 @@ samples:
- url: images/web_dashboard1.png - url: images/web_dashboard1.png
alt: Web Dashboard screenshot alt: Web Dashboard screenshot
- url: images/web_dashboard2.png - url: images/web_dashboard2.png
alt: Web Dashbaord screenshot alt: Web Dashboard screenshot
- url: images/web_dashboard3.png - url: images/web_dashboard3.png
alt: Web Dashboard screenshot alt: Web Dashboard screenshot
source: https://github.com/flutter/samples/tree/main/experimental/web_dashboard source: https://github.com/flutter/samples/tree/main/experimental/web_dashboard

View File

@@ -6,8 +6,11 @@ bool matchesQuery(String query, String sampleAttributes) {
if (query.isEmpty) { if (query.isEmpty) {
return true; 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 // Test for type filter
// This will check whether a type parameter is present in the // This will check whether a type parameter is present in the

View File

@@ -107,7 +107,9 @@ void main() {
// Test if various queries match these attributes // Test if various queries match these attributes
expect(matchesQuery('foo', attributes), false); expect(matchesQuery('foo', attributes), false);
expect(matchesQuery('Foo', attributes), false);
expect(matchesQuery('kittens', attributes), true); expect(matchesQuery('kittens', attributes), true);
expect(matchesQuery('Kittens', attributes), true);
expect(matchesQuery('tag:cats', attributes), true); expect(matchesQuery('tag:cats', attributes), true);
expect(matchesQuery('tag:dogs', attributes), false); expect(matchesQuery('tag:dogs', attributes), false);
expect(matchesQuery('package:path', attributes), true); expect(matchesQuery('package:path', attributes), true);