fix: adjust multi-tag search so space groups tags together and 'and' splits independent query streams
This commit is contained in:
@@ -165,29 +165,24 @@ class ProviderManager {
|
|||||||
|
|
||||||
static List<List<String>> splitTagGroups(List<String> rawTags) {
|
static List<List<String>> splitTagGroups(List<String> rawTags) {
|
||||||
final groups = <List<String>>[];
|
final groups = <List<String>>[];
|
||||||
List<String> currentAndGroup = [];
|
List<String> currentGroup = [];
|
||||||
|
|
||||||
for (int i = 0; i < rawTags.length; i++) {
|
for (final raw in rawTags) {
|
||||||
final token = rawTags[i].trim();
|
final token = raw.trim();
|
||||||
if (token.isEmpty) continue;
|
if (token.isEmpty) continue;
|
||||||
|
|
||||||
if (token.toLowerCase() == 'and') {
|
if (token.toLowerCase() == 'and') {
|
||||||
continue;
|
if (currentGroup.isNotEmpty) {
|
||||||
}
|
groups.add(currentGroup);
|
||||||
|
currentGroup = [];
|
||||||
final prevWasAnd = i > 0 && rawTags[i - 1].trim().toLowerCase() == 'and';
|
|
||||||
if (prevWasAnd) {
|
|
||||||
currentAndGroup.add(token);
|
|
||||||
} else {
|
|
||||||
if (currentAndGroup.isNotEmpty) {
|
|
||||||
groups.add(currentAndGroup);
|
|
||||||
}
|
}
|
||||||
currentAndGroup = [token];
|
} else {
|
||||||
|
currentGroup.add(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentAndGroup.isNotEmpty) {
|
if (currentGroup.isNotEmpty) {
|
||||||
groups.add(currentAndGroup);
|
groups.add(currentGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
return groups.isEmpty ? [const []] : groups;
|
return groups.isEmpty ? [const []] : groups;
|
||||||
|
|||||||
@@ -2,49 +2,46 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
import 'package:gel_rule_app/backend/providers/provider_manager.dart';
|
import 'package:gel_rule_app/backend/providers/provider_manager.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('Tag groups splitting with local and connector', () {
|
group('Tag groups splitting: space groups together, and separates streams', () {
|
||||||
test('single tag returns one group', () {
|
test('single tag returns one group', () {
|
||||||
final groups = ProviderManager.splitTagGroups(['cat']);
|
final groups = ProviderManager.splitTagGroups(['cat']);
|
||||||
expect(groups, equals([['cat']]));
|
expect(groups, equals([['cat']]));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('multiple tags without and are split into separate independent groups', () {
|
test('tags separated by space are grouped together in one query', () {
|
||||||
final groups = ProviderManager.splitTagGroups(['cat', 'dog', 'bird']);
|
final groups = ProviderManager.splitTagGroups(['raiden', 'miku']);
|
||||||
expect(groups, equals([
|
expect(groups, equals([
|
||||||
['cat'],
|
['raiden', 'miku'],
|
||||||
['dog'],
|
|
||||||
['bird'],
|
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('tags connected by and are merged into the same group', () {
|
test('tags separated by and are split into independent query streams', () {
|
||||||
final groups = ProviderManager.splitTagGroups(['cat', 'and', 'dog']);
|
final groups = ProviderManager.splitTagGroups(['raiden', 'and', 'miku']);
|
||||||
expect(groups, equals([
|
expect(groups, equals([
|
||||||
['cat', 'dog'],
|
['raiden'],
|
||||||
|
['miku'],
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('mixed independent tags and and-connected tags', () {
|
test('multiple multi-tag groups separated by and', () {
|
||||||
final groups = ProviderManager.splitTagGroups([
|
final groups = ProviderManager.splitTagGroups([
|
||||||
'genshin',
|
'genshin',
|
||||||
'and',
|
|
||||||
'raiden',
|
'raiden',
|
||||||
'miku',
|
|
||||||
'vocaloid',
|
|
||||||
'and',
|
'and',
|
||||||
'hatsune',
|
'vocaloid',
|
||||||
|
'miku',
|
||||||
]);
|
]);
|
||||||
expect(groups, equals([
|
expect(groups, equals([
|
||||||
['genshin', 'raiden'],
|
['genshin', 'raiden'],
|
||||||
['miku'],
|
['vocaloid', 'miku'],
|
||||||
['vocaloid', 'hatsune'],
|
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('case-insensitive AND handling', () {
|
test('case-insensitive AND separator', () {
|
||||||
final groups = ProviderManager.splitTagGroups(['2girls', 'AND', 'yuri']);
|
final groups = ProviderManager.splitTagGroups(['cat', 'AND', 'dog']);
|
||||||
expect(groups, equals([
|
expect(groups, equals([
|
||||||
['2girls', 'yuri'],
|
['cat'],
|
||||||
|
['dog'],
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user