Skip to content

feat: Frontend Search with Client-side Index#1

Merged
weekendfish merged 20 commits intomainfrom
feature/frontend-search
Feb 23, 2026
Merged

feat: Frontend Search with Client-side Index#1
weekendfish merged 20 commits intomainfrom
feature/frontend-search

Conversation

@weekendfish
Copy link
Copy Markdown
Contributor

变更

  • 将搜索从后端 API 改为前端客户端搜索
  • 使用 pako 解压 gzip 索引文件
  • 支持 10 个仓库索引(13MB)
  • 保留原有 SearchForm + SearchResults 界面
  • 支持关键词、域名、标签、年份、地区筛选

优势

  • ⚡ 更快:本地解压搜索,无需网络请求
  • 🌐 离线可用:索引下载后可离线搜索
  • 💰 零成本:无需后端服务器

测试

待办

  • 需要更新 GitHub Actions 部署到 CF Pages
  • 需要配置 Cloudflare Pages 生产环境

fishcat added 4 commits February 23, 2026 02:12
- Add dual deployment to test and production environments
- Add wrangler.toml.prod for production config
- Trigger on main branch push
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements a significant architectural change by migrating the search functionality from a backend API to a client-side implementation using pre-built compressed indexes. The main goal is to enable faster, offline-capable search without requiring backend infrastructure.

Changes:

  • Added client-side search using compressed gzip indexes with the pako library for decompression
  • Replaced server-side search API calls with local index loading and filtering
  • Updated ES module import syntax from assert to with for JSON imports
  • Added Cloudflare Wrangler configuration files for deployment
  • Modified GitHub Actions workflow to deploy to both production and test Cloudflare Pages environments

Reviewed changes

Copilot reviewed 7 out of 22 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
components/search/useClientSearch.ts New React hook implementing client-side search with index loading, caching, and filtering logic
app/search/page.tsx Simplified search page component to use the new client-side search hook instead of API calls
package.json & package-lock.json & yarn.lock Added pako v2.1.0 dependency for gzip decompression
scripts/rss.mjs Updated JSON import syntax from assert to with (ES modules import attributes)
wrangler.toml & wrangler.toml.prod New Cloudflare Wrangler configuration files for test and production deployments
.github/workflows/cf-pages-deploy.yml Updated workflow to deploy to both production and test Cloudflare Pages environments
public/search-index/repo-*.json.gz Binary compressed search index files (not reviewed in detail as they are data files)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread components/search/useClientSearch.ts Outdated
Comment thread components/search/useClientSearch.ts Outdated
Comment thread components/search/useClientSearch.ts Outdated
Comment thread components/search/useClientSearch.ts Outdated
Comment thread components/search/useClientSearch.ts Outdated
Comment thread components/search/useClientSearch.ts Outdated
Comment thread components/search/useClientSearch.ts Outdated
Comment thread .github/workflows/cf-pages-deploy.yml
Comment thread app/search/page.tsx Outdated
Comment thread app/search/page.tsx Outdated
fishcat and others added 7 commits February 23, 2026 04:23
- Restore URL update with router.push()
- Restore tsindex.org banner
- Restore page title 条目检索
- Restore complete initialValues for SearchForm
- Restore Suspense boundary
- Keep frontend search logic
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Add all 10 domains to REPO_INDEXES
- Add IndexDocument interface instead of any
- Fix performance: check limit before inner loop
- Add RESULT_LIMIT constant
- Remove duplicate url/link (keep url only)
- Use environment variable for account_id
- Throw error to UI instead of just console
- Improve Chinese search support
- Fix URL update with router.push
- Keep initialValues for all fields
- Deploy to transchinese-test on pull requests
- Deploy to transchinese-org on main branch push
- Separate jobs for preview and production
- Add lib/clientSearch.ts for client-side search
- Replace API call with clientSearch() in page.tsx
- Keep all original UI and functionality
- Remove useClientSearch.ts hook (replaced by lib/clientSearch)
@yunwei37 yunwei37 requested a review from Copilot February 23, 2026 04:13
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 23 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/clientSearch.ts Outdated
Comment thread lib/clientSearch.ts Outdated
Comment thread lib/clientSearch.ts Outdated
Comment thread .github/workflows/cf-pages-deploy.yml Outdated
Comment thread lib/clientSearch.ts Outdated
Comment thread scripts/rss.mjs Outdated
Comment thread wrangler.toml.prod Outdated
Comment thread lib/clientSearch.ts Outdated
const file = REPO_INDEXES[domain]
if (!file) return null
try {
const res = await fetch(file)
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadIndex does not check res.ok before inflating; a 404/500 response body will be passed to pako.inflate and then JSON.parse, producing confusing errors. Add an if (!res.ok) branch (and ideally include status/url in the error) before reading/decompressing.

Suggested change
const res = await fetch(file)
const res = await fetch(file)
if (!res.ok) {
console.error(
'Failed to fetch search index',
{ domain, file, status: res.status, statusText: res.statusText }
)
return null
}

Copilot uses AI. Check for mistakes.
fishcat and others added 5 commits February 23, 2026 05:22
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Add workflow_dispatch support for deploy-preview
- Remove continue-on-error to show real failures
- Restore account_id in wrangler.toml.prod
- Remove ENDFILE (empty file)
- Remove EOF (empty file)
- Remove search-index.json.gz (duplicate, already in public/search-index/)
@weekendfish weekendfish merged commit fa25bcf into main Feb 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants