Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

I Built a Search Engine With Zero Dependencies — Just Python 3.14's Standard Library

说明与用途

SwiftSearch 展示了如何仅使用 Python 3.14 标准库实现全文搜索,无需任何第三方依赖。

问题

Modern web apps often add heavy search stacks (Elasticsearch, Whoosh, FastAPI, etc.) that inflate dependencies, runtime, and complexity for simple local search needs.

结果

SwiftSearch demonstrates that a lightweight, dependency‑free search engine can be built with only Python’s standard library, achieving sub‑millisecond query times and eliminating external services.

工作流

  • 1. Build an inverted index in memory with collections.defaultdict and dataclasses to store postings and document frequencies.
  • 2. Tokenize text using unicodedata.normalize('NFC') and a simple alphanumeric split.
  • 3. Serve HTTP requests with http.server, handling dual routing (API and static assets) by inspecting self.path and setting headers manually.
  • 4. Return JSON search results and render a demo page for the command‑palette UI.
  • 5. Verify zero external imports with a grep check across the codebase.
  • 6. Run the server with python -m swiftsearch serve and perform queries like /search?q=python.

证据

SwiftSearch runs with a single command (python -m swiftsearch serve), using only stdlib modules: collections.defaultdict for inverted indexing, unicodedata for tokenization, http.server for the API, and a simple linear scoring formula.

来源

Every import resolved to a Python 3.14 built‑in: argparse, collections, dataclasses, html, http.server, json, pathlib, time, unicodedata, urllib.parse.

来源

  • 记录日期: 2026-09-11T04:01:14.660Z