docs: add doc indexing script (rg/json + sqlite FTS)

This commit is contained in:
2026-02-14 23:44:46 +01:00
parent 9cd69351f0
commit 26a501b6dd

42
scripts/build-doc-index.sh Executable file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -euo pipefail
# Build a simple ripgrep JSON index of docs and a sqlite FTS index (if sqlite3 available)
OUT_JSON=workspace/docs-index.json
mkdir -p workspace
if command -v rg >/dev/null 2>&1; then
rg --no-ignore -n --hidden --glob '!node_modules' --json "" docs | jq -s '.' > "$OUT_JSON"
echo "Wrote $OUT_JSON"
else
echo "ripgrep (rg) not found. Please run scripts/install-cli-tools.sh"
exit 2
fi
if command -v sqlite3 >/dev/null 2>&1; then
SQL_DB=workspace/docs-index.db
echo "Creating sqlite FTS db at $SQL_DB"
sqlite3 "$SQL_DB" <<'SQL'
CREATE VIRTUAL TABLE IF NOT EXISTS docs USING fts5(path,content);
SQL
# Populate: for each file in docs, insert path and content
python3 - <<'PY'
import os,sqlite3
db='workspace/docs-index.db'
conn=sqlite3.connect(db)
c=conn.cursor()
for root,_,files in os.walk('docs'):
for f in files:
p=os.path.join(root,f)
try:
with open(p,'r',encoding='utf-8') as fh:
content=fh.read()
except Exception:
continue
c.execute('INSERT INTO docs(path,content) VALUES (?,?)',(p,content))
conn.commit(); conn.close()
print('Inserted docs')
PY
echo "SQLite FTS built"
else
echo "sqlite3 not found; skipping sqlite FTS build"
fi