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 String? providerId,
required TopPeriodFilter topPeriod, required TopPeriodFilter topPeriod,
}) async { }) async {
final cleanTags = tags
.map((t) => t.trim())
.where((t) => t.isNotEmpty && t.toLowerCase() != 'and')
.toList(growable: false);
final seen = <String>{}; final seen = <String>{};
final providerResults = <List<Post>>[]; final providerResults = <List<Post>>[];
for (final provider in providers) { for (final provider in providers) {
try { try {
final providerPosts = await provider.searchPosts( final providerPosts = await provider.searchPosts(
tags: tags, tags: cleanTags,
page: page, page: page,
limit: limit, limit: limit,
rating: rating, rating: rating,
+15 -6
View File
@@ -112,13 +112,21 @@ class FeedService {
} }
bool postMatchesRequestedTags(Post post, List<String> requestedTags) { bool postMatchesRequestedTags(Post post, List<String> requestedTags) {
final requested = requestedTags if (post.providerId == 'pawchive') return true;
.map((tag) => tag.trim().toLowerCase())
.where((tag) => tag.isNotEmpty && !tag.startsWith('-')) final groups = ProviderManager.splitTagGroups(requestedTags);
.toList(growable: false); if (groups.isEmpty) return true;
if (requested.isEmpty) return true;
final postTags = _postTagSet(post); final postTags = _postTagSet(post);
return requested.every( 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( (requestedTag) => postTags.any(
(postTag) => (postTag) =>
postTag == requestedTag || postTag == requestedTag ||
@@ -126,6 +134,7 @@ bool postMatchesRequestedTags(Post post, List<String> requestedTags) {
postTag.startsWith('$requestedTag-'), postTag.startsWith('$requestedTag-'),
), ),
); );
});
} }
bool postPassesTagFilters(Post post, AppSettings settings) { bool postPassesTagFilters(Post post, AppSettings settings) {
+2 -1
View File
@@ -43,11 +43,12 @@ void main() {
expect(postPassesTagFilters(post, settings), isFalse); 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']); final post = _post(tags: ['touhou', 'hakurei_reimu']);
expect(postMatchesRequestedTags(post, ['touhou']), isTrue); expect(postMatchesRequestedTags(post, ['touhou']), isTrue);
expect(postMatchesRequestedTags(post, ['touhou', 'cirno']), isFalse); expect(postMatchesRequestedTags(post, ['touhou', 'cirno']), isFalse);
expect(postMatchesRequestedTags(post, ['touhou', 'and', 'cirno']), isTrue);
}); });
test('requested search tags can match tag prefixes', () { test('requested search tags can match tag prefixes', () {