fix: resolve No post yet by adapting postMatchesRequestedTags to tag groups and filtering 'and' from provider queries

This commit is contained in:
2026-09-03 21:15:01 +03:00
parent a8b778146d
commit fb31a303ff
3 changed files with 30 additions and 15 deletions
+6 -1
View File
@@ -257,12 +257,17 @@ class ProviderManager {
required String? providerId,
required TopPeriodFilter topPeriod,
}) async {
final cleanTags = tags
.map((t) => t.trim())
.where((t) => t.isNotEmpty && t.toLowerCase() != 'and')
.toList(growable: false);
final seen = <String>{};
final providerResults = <List<Post>>[];
for (final provider in providers) {
try {
final providerPosts = await provider.searchPosts(
tags: tags,
tags: cleanTags,
page: page,
limit: limit,
rating: rating,
+22 -13
View File
@@ -112,20 +112,29 @@ class FeedService {
}
bool postMatchesRequestedTags(Post post, List<String> requestedTags) {
final requested = requestedTags
.map((tag) => tag.trim().toLowerCase())
.where((tag) => tag.isNotEmpty && !tag.startsWith('-'))
.toList(growable: false);
if (requested.isEmpty) return true;
if (post.providerId == 'pawchive') return true;
final groups = ProviderManager.splitTagGroups(requestedTags);
if (groups.isEmpty) return true;
final postTags = _postTagSet(post);
return requested.every(
(requestedTag) => postTags.any(
(postTag) =>
postTag == requestedTag ||
postTag.startsWith('${requestedTag}_') ||
postTag.startsWith('$requestedTag-'),
),
);
if (postTags.isEmpty) return true;
return groups.any((group) {
final cleanGroup = group
.map((tag) => tag.trim().toLowerCase())
.where((tag) => tag.isNotEmpty && !tag.startsWith('-') && tag != 'and')
.toList(growable: false);
if (cleanGroup.isEmpty) return true;
return cleanGroup.every(
(requestedTag) => postTags.any(
(postTag) =>
postTag == requestedTag ||
postTag.startsWith('${requestedTag}_') ||
postTag.startsWith('$requestedTag-'),
),
);
});
}
bool postPassesTagFilters(Post post, AppSettings settings) {
+2 -1
View File
@@ -43,11 +43,12 @@ void main() {
expect(postPassesTagFilters(post, settings), isFalse);
});
test('requested search tags are all required', () {
test('requested search tags are all required unless separated by and', () {
final post = _post(tags: ['touhou', 'hakurei_reimu']);
expect(postMatchesRequestedTags(post, ['touhou']), isTrue);
expect(postMatchesRequestedTags(post, ['touhou', 'cirno']), isFalse);
expect(postMatchesRequestedTags(post, ['touhou', 'and', 'cirno']), isTrue);
});
test('requested search tags can match tag prefixes', () {