feat: add compare, trends routes, embedder service, and phase5 tests

This commit is contained in:
2026-06-05 23:32:06 +08:00
parent 2cfd1a8a9f
commit ba9afa212c
17 changed files with 2122 additions and 27 deletions
+1
View File
@@ -16,6 +16,7 @@
<div class="nav-links">
<a href="/day/{{ today if today else '' }}">今日</a>
<a href="/search">搜索</a>
<a href="/trends">趋势</a>
<a href="/reading-list">阅读列表</a>
<a href="/admin/logs">管理</a>
</div>
+86
View File
@@ -0,0 +1,86 @@
{% extends "base.html" %}
{% block title %}{{ page_title }} — HF Daily Papers{% endblock %}
{% block content %}
<section class="compare-page">
<h1>论文对比</h1>
{# ID 输入表单 #}
<form class="search-form" method="get" action="/compare">
<input type="text" name="ids" value="{{ ids_param }}"
placeholder="输入 arXiv ID,逗号分隔(最多 5 篇),如 2401.12345,2401.67890"
class="search-input">
<button type="submit" class="search-btn">对比</button>
</form>
{% if error %}
<div class="empty-state">
<p>{{ error }}</p>
</div>
{% endif %}
{% if papers %}
<div class="compare-table-wrapper">
<table class="compare-table">
<thead>
<tr>
<th>字段</th>
{% for paper in papers %}
<th>
<a href="/paper/{{ paper.arxiv_id }}">{{ paper.arxiv_id }}</a>
<br>
<small style="color: var(--ink-light);">
{{ paper.upvotes }} 👍 · {{ paper.paper_date }}
</small>
</th>
{% endfor %}
</tr>
</thead>
<tbody>
{# 作者行 #}
<tr>
<td class="field-label">作者</td>
{% for paper in papers %}
<td class="paper-col">{{ paper.authors|map(attribute='name')|join(', ') }}</td>
{% endfor %}
</tr>
{# 标签行 #}
<tr>
<td class="field-label">标签</td>
{% for paper in papers %}
<td class="paper-col">
{% for t in paper.tags[:5] %}
<span class="tag">{{ t.tag }}</span>
{% endfor %}
</td>
{% endfor %}
</tr>
{# 结构化对比字段 #}
{% for row in rows %}
<tr>
<td class="field-label">{{ row.label }}</td>
{% for cell in row.cells %}
<td class="paper-col">
{% if cell %}
{{ cell }}
{% else %}
<span class="no-summary">暂无总结</span>
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% elif ids_param and not error %}
<div class="empty-state">
<p>未找到匹配的论文</p>
<p class="hint">请检查 arXiv ID 是否正确</p>
</div>
{% endif %}
</section>
{% endblock %}
+30
View File
@@ -117,5 +117,35 @@
<p class="abstract-en">{{ paper.abstract }}</p>
</section>
{% endif %}
{# Phase 5: 图片画廊 #}
{% if paper_images %}
<section class="image-gallery">
<h2>论文图片</h2>
<div class="gallery-grid">
{% for img in paper_images %}
<div class="gallery-item">
<img src="{{ img.url }}" alt="{{ img.name }}" loading="lazy">
<div class="gallery-caption">{{ img.name }}</div>
</div>
{% endfor %}
</div>
</section>
{% endif %}
{# Phase 5: 相似论文推荐 #}
{% if similar_papers %}
<section class="similar-papers">
<h2>相似论文推荐</h2>
{% for sp in similar_papers %}
<div class="similar-paper-item">
<span class="similar-paper-title">
<a href="/paper/{{ sp.arxiv_id }}">{{ sp.title_zh }}</a>
</span>
<span class="similar-paper-dist">🎯 {{ "%.3f"|format(sp.distance) }}</span>
</div>
{% endfor %}
</section>
{% endif %}
</article>
{% endblock %}
+27 -7
View File
@@ -11,6 +11,21 @@
{% if tag %}
<input type="hidden" name="tag" value="{{ tag }}">
{% endif %}
{# 模式切换 #}
{% if chroma_enabled %}
<div class="search-mode-toggle">
<label class="mode-option {% if mode == 'keyword' or not mode %}active{% endif %}">
<input type="radio" name="mode" value="keyword" {% if mode == 'keyword' or not mode %}checked{% endif %}>
关键词
</label>
<label class="mode-option {% if mode == 'semantic' %}active{% endif %}">
<input type="radio" name="mode" value="semantic" {% if mode == 'semantic' %}checked{% endif %}>
语义搜索
</label>
</div>
{% endif %}
<button type="submit" class="search-btn">搜索</button>
</form>
@@ -18,10 +33,10 @@
{% if all_tags %}
<div class="tag-filter">
<span class="tag-filter-label">标签:</span>
<a href="/search{% if query %}?q={{ query }}{% endif %}"
<a href="/search?q={{ query }}&mode={{ mode }}{% if tag %}&tag={{ tag }}{% endif %}"
class="tag-chip {% if not tag %}active{% endif %}">全部</a>
{% for t in all_tags %}
<a href="/search?q={{ query }}&tag={{ t }}"
<a href="/search?q={{ query }}&tag={{ t }}&mode={{ mode }}"
class="tag-chip {% if t == tag %}active{% endif %}">{{ t }}</a>
{% endfor %}
</div>
@@ -30,12 +45,12 @@
{% if query or tag %}
{# 搜索结果元信息 #}
<div class="search-meta">
<span>找到 {{ total }} 条结果</span>
<span>找到 {{ total }} 条结果{% if mode == 'semantic' %}(语义模式){% endif %}</span>
<div class="sort-toggle">
<a href="/search?q={{ query }}&tag={{ tag }}&sort=relevance"
<a href="/search?q={{ query }}&tag={{ tag }}&mode={{ mode }}&sort=relevance"
class="{% if sort == 'relevance' %}active{% endif %}">相关性</a>
<span class="sort-divider">|</span>
<a href="/search?q={{ query }}&tag={{ tag }}&sort=date"
<a href="/search?q={{ query }}&tag={{ tag }}&mode={{ mode }}&sort=date"
class="{% if sort == 'date' %}active{% endif %}">日期</a>
</div>
</div>
@@ -58,6 +73,11 @@
</a>
</h2>
<span class="paper-upvotes">👍 {{ paper.upvotes }}</span>
{% if distances and paper.arxiv_id in distances %}
<span class="similarity-score" title="语义相似度距离">
🎯 {{ "%.3f"|format(distances[paper.arxiv_id]) }}
</span>
{% endif %}
</div>
{% if snippet and snippet.abstract %}
@@ -103,11 +123,11 @@
{% if total_pages > 1 %}
<nav class="pagination">
{% if page > 1 %}
<a href="/search?q={{ query }}&tag={{ tag }}&sort={{ sort }}&page={{ page - 1 }}" class="page-btn">← 上一页</a>
<a href="/search?q={{ query }}&tag={{ tag }}&sort={{ sort }}&mode={{ mode }}&page={{ page - 1 }}" class="page-btn">← 上一页</a>
{% endif %}
<span class="page-info">{{ page }} / {{ total_pages }}</span>
{% if page < total_pages %}
<a href="/search?q={{ query }}&tag={{ tag }}&sort={{ sort }}&page={{ page + 1 }}" class="page-btn">下一页 →</a>
<a href="/search?q={{ query }}&tag={{ tag }}&sort={{ sort }}&mode={{ mode }}&page={{ page + 1 }}" class="page-btn">下一页 →</a>
{% endif %}
</nav>
{% endif %}
+185
View File
@@ -0,0 +1,185 @@
{% extends "base.html" %}
{% block title %}{{ page_title }} — HF Daily Papers{% endblock %}
{% block content %}
<section class="trends-page">
<h1>趋势看板</h1>
<div class="charts-grid">
{# 按日论文数量折线图 #}
<div class="chart-card">
<h2>📅 每日论文数量(近 30 天)</h2>
<canvas id="dailyChart"></canvas>
</div>
{# 热门标签 Top 20 #}
<div class="chart-card">
<h2>🏷️ 热门标签 Top 20</h2>
<canvas id="tagsChart"></canvas>
</div>
{# Upvotes 分布 #}
<div class="chart-card">
<h2>👍 Upvotes 分布</h2>
<canvas id="upvotesChart"></canvas>
</div>
{# 总结完成率 #}
<div class="chart-card">
<h2>📝 总结完成率</h2>
<canvas id="summaryChart"></canvas>
</div>
</div>
</section>
{% endblock %}
{% block scripts %}
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.7/dist/chart.umd.min.js"></script>
<script>
// 颜色配置(kami 风格墨蓝色系)
const COLORS = {
primary: '#2d5f8a',
primaryLight: 'rgba(45, 95, 138, 0.2)',
accent: '#5a9bc7',
success: '#388e3c',
warning: '#f57f17',
danger: '#c62828',
muted: '#4a4a6a',
palette: [
'#2d5f8a', '#5a9bc7', '#388e3c', '#f57f17', '#c62828',
'#7b1fa2', '#00838f', '#ef6c00', '#455a64', '#827717',
'#1565c0', '#ad1457', '#00695c', '#e65100', '#283593',
'#9e9d24', '#6a1b9a', '#00838f', '#4e342e', '#37474f',
],
};
const statsData = {{ stats | tojson }};
// 每日论文数量折线图
(function() {
const ctx = document.getElementById('dailyChart').getContext('2d');
const labels = statsData.daily_counts.map(d => d.date);
const data = statsData.daily_counts.map(d => d.count);
new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: '论文数',
data: data,
borderColor: COLORS.primary,
backgroundColor: COLORS.primaryLight,
fill: true,
tension: 0.3,
pointRadius: 3,
pointHoverRadius: 6,
}]
},
options: {
responsive: true,
plugins: { legend: { display: false } },
scales: {
x: { ticks: { maxTicksLimit: 10, font: { size: 11 } } },
y: { beginAtZero: true, ticks: { stepSize: 1 } },
}
}
});
})();
// 热门标签柱状图
(function() {
const ctx = document.getElementById('tagsChart').getContext('2d');
const labels = statsData.top_tags.map(d => d.tag);
const data = statsData.top_tags.map(d => d.count);
new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: '论文数',
data: data,
backgroundColor: COLORS.palette.slice(0, data.length),
borderRadius: 4,
}]
},
options: {
responsive: true,
indexAxis: 'y',
plugins: { legend: { display: false } },
scales: {
x: { beginAtZero: true, ticks: { stepSize: 1 } },
}
}
});
})();
// Upvotes 分布
(function() {
const ctx = document.getElementById('upvotesChart').getContext('2d');
const labels = statsData.upvotes_dist.map(d => d.range);
const data = statsData.upvotes_dist.map(d => d.count);
new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: '论文数',
data: data,
backgroundColor: COLORS.accent,
borderRadius: 4,
}]
},
options: {
responsive: true,
plugins: { legend: { display: false } },
scales: {
y: { beginAtZero: true, ticks: { stepSize: 1 } },
}
}
});
})();
// 总结完成率环形图
(function() {
const ctx = document.getElementById('summaryChart').getContext('2d');
const statusLabels = {
'done': '已完成',
'pending': '待总结',
'processing': '总结中',
'failed': '失败',
'permanent_failure': '永久失败',
'none': '未开始',
};
const statusColors = {
'done': COLORS.success,
'pending': COLORS.warning,
'processing': COLORS.primary,
'failed': COLORS.danger,
'permanent_failure': '#b71c1c',
'none': '#bdbdbd',
};
const labels = statsData.summary_completion.map(d => statusLabels[d.status] || d.status);
const data = statsData.summary_completion.map(d => d.count);
const colors = statsData.summary_completion.map(d => statusColors[d.status] || COLORS.muted);
new Chart(ctx, {
type: 'doughnut',
data: {
labels: labels,
datasets: [{
data: data,
backgroundColor: colors,
borderWidth: 2,
borderColor: '#fff',
}]
},
options: {
responsive: true,
plugins: {
legend: { position: 'bottom', labels: { padding: 12 } },
}
}
});
})();
</script>
{% endblock %}