MA↗Mohamed
Abderrehmane
← All work
12 / Python · Flask · SQLite · mmap · optional Cython

Local Text SearchLocal corpus search with background jobs

Search local text files asynchronously and let users inspect progress, paginate matches and download output.

Local Text Search — actual application interface with demonstration data
Application interface · demo data
01

The problem & workflow

Authenticated user creates a search → worker scans configured synthetic corpus → job progress and output file are updated → owner browses/downloads results → administrator reviews usage.

Key features

  • Memory-mapped text scanning and Python fallback
  • Optional Cython acceleration
  • Background job progress and batched result-file writes
  • Result pagination/downloads and owner checks
  • User/admin management and usage statistics
  • Optional Telegram ingestion, disabled by default
02

Architecture & decisions

Local Text Search — component relationships
  • Corpus, database and output directories resolve through one module instead of the old machine-specific Downloads path. Authentication and web handlers must use the same database.
  • mmap avoids loading each entire file into a Python string. Case-insensitive matching currently lowers byte strings; this is not general Unicode case folding.
  • Windows uses the threaded worker path; other platforms retain multiprocessing-related code. Describe measured behavior on the tested OS.
  • Optional Telegram and acceleration packages are split from the minimal Flask install. Enabling one integration should be deliberate.
  • Session secrets can persist through an environment value; generating a new key at restart invalidates existing sessions.

Inside the source

03

Keeping long-running corpus search outside a web request

I built this local search application with Flask, background jobs and memory-mapped file scanning.

Local Text Search uses Flask for the user and administration experience while background jobs scan memory-mapped files. SQLite stores job metadata, batched result files hold matches, and the interface polls progress before showing paginated results or a download. Result ownership is checked at the application boundary.

Worker behavior depends on the platform. The documented Windows path uses threading, and the optional Cython matcher is a separate build path. One configuration source now controls corpus, database, result and session locations, so a configurable corpus no longer conflicts with a hard-coded search-engine default.

A result limit must be shared across workers

Giving each file worker its own limit can return more results than a user requested. The release uses a shared result budget and checks matching across long lines, mixed bytes and multiple files. Six regression/access tests cover those cases and cross-user boundaries; interrupted jobs and acceleration equivalence remain further verification tasks.

The benchmark uses 800,000 generated lines and documents bytes, matches, Windows hardware, Python version and three measured times. OS caches were not flushed and Cython was not enabled. These details make the measurement reproducible without presenting an unmeasured speedup or a claim about terabyte-scale production data.

04

Project status

Local corpus-processing and administration application. Public demos use generated text only.

Use Python 3.12 for the recorded checks. Export .env.example values into the process; config.py resolves relative paths from the application root. Set a persistent SECRET_KEY for sessions and ENABLE_TELEGRAM=0. bootstrap_demo.py prompts for a fresh 12-character administrator password and writes generated text only when absent. Cython is optional and requires a compiler; Python remains the default verified path.

Development checks & runtime notes

All six Python regression/access tests passed: long lines and AND matching, zero/mixed-byte cases, a shared result budget across files, job ownership, unauthenticated search, and a 1,000-line matching regression. A measured Windows Python-only benchmark found exactly 800 matches in 800,000 generated lines (36,353,960 bytes); three runs took 10.2452, 10.9746 and 10.5983 seconds. OS caches were not flushed.

Cython equivalence, Linux worker behavior and interrupted-job recovery remain unverified. Included benchmark is Python-only on the documented Windows machine, not a speedup comparison. Optional Telegram ingestion is disabled for demos.

Technical details ↗
NEXT PROJECTLahda ↗
LET’S TALK

Have a project in mind?

Tell me about the app or website you want to build.

Contact on WhatsApp +213794873386 ↗