feat(app): 推荐流支持分类过滤
This commit is contained in:
1 parent
0e8fb1582d
commit
8f35160b56
12 files changed
+255
-24
No files matched your search
+13
@@ -99,6 +99,19 @@ final class DramaMultiTagSupport {
|
||||
});
|
||||
}
|
||||
|
||||
static void applyCategoryIdTokens(QueryWrapper<Drama> wrapper,
|
||||
List<Long> categoryIds) {
|
||||
wrapper.and(nested -> {
|
||||
for (int index = 0; index < categoryIds.size(); index++) {
|
||||
if (index > 0) {
|
||||
nested.or();
|
||||
}
|
||||
nested.apply("(',' || category_ids || ',') LIKE {0}",
|
||||
tokenPattern(categoryIds.get(index)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static List<String> parseDramaTypes(Drama drama) {
|
||||
List<String> values = parseStringTokens(drama.getDramaTypes()).stream()
|
||||
.map(DramaMultiTagSupport::normalizeDramaType)
|
||||
|
||||
+8
-2
@@ -237,20 +237,26 @@ public class DramaService {
|
||||
* App 推荐流:按推荐权重、热度、ID 倒序,并支持内容类型多选。
|
||||
* cursor 使用上一页最后一条 ID,服务端反查排序键后做 keyset 查询。
|
||||
*/
|
||||
public List<Drama> listPublishedFeed(List<String> dramaTypes, Long cursor, int limit) {
|
||||
public List<Drama> listPublishedFeed(
|
||||
List<String> dramaTypes, Long categoryId, Long cursor, int limit) {
|
||||
List<String> normalizedTypes = DramaMultiTagSupport.normalizeDramaTypes(dramaTypes);
|
||||
QueryWrapper<Drama> query = new QueryWrapper<>();
|
||||
query.eq("status", ContentStatus.PUBLISHED.getCode());
|
||||
if (!normalizedTypes.isEmpty()) {
|
||||
DramaMultiTagSupport.applyDramaTypeTokens(query, normalizedTypes);
|
||||
}
|
||||
if (categoryId != null) {
|
||||
DramaMultiTagSupport.applyCategoryIdTokens(query, List.of(categoryId));
|
||||
}
|
||||
if (cursor != null) {
|
||||
Drama marker = dramaMapper.selectById(cursor);
|
||||
if (marker == null
|
||||
|| !ContentStatus.PUBLISHED.getCode().equals(marker.getStatus())
|
||||
|| (!normalizedTypes.isEmpty()
|
||||
&& DramaMultiTagSupport.parseDramaTypes(marker).stream()
|
||||
.noneMatch(normalizedTypes::contains))) {
|
||||
.noneMatch(normalizedTypes::contains))
|
||||
|| (categoryId != null
|
||||
&& !DramaMultiTagSupport.parseCategoryIds(marker).contains(categoryId))) {
|
||||
return List.of();
|
||||
}
|
||||
applyFeedCursor(query, marker);
|
||||
|
||||
Reference in new issue
Block a user