# ISE — Intelligent Search Engine **The complete manual: operator guide and script reference. Master v9.2 (2026-12-04).** One manual for the ISE search mod on drugs-and-users.org and for every script and tool around it. It replaces `ISE_Python_Scripts_Manual.md` and every separate per-script manual and manual entry. `ISE_help.html` stays separate, because it is the in-app help for forum users (§8). - Every script prints its own version once as it starts, and its doc-block holds its full history. Where this manual and a script disagree, the script is right. - Points this manual could not settle from the material it was built from are marked **Check:**. ## Contents **Part 1 — Operator guide** 1. What ISE does 2. Where things run 3. File layout 4. Installing and uninstalling 5. Building and refreshing the indexes 6. The `#do-not-index` tag 7. Searching: words, quotes, wildcards, AND/OR, sorting, result caps 8. In-app help (`/help`) 9. The reset checkboxes 10. Known quirks of this SMF fork 11. Troubleshooting **Part 2 — Script reference** 12. Two codebases, two settings mechanisms 13. IndexBuilder.py and search.py (posts) 14. PDFIndexer.py (and PDF-32bit-Indexer.py) 15. PDFsearch.py 16. MiscIndexer.py 17. MiscSearch.py 18. MegaSearch.py 19. MediaIndexer.py 20. MediaProcessor.py 21. MediaSearch.py 22. AudioProcessor.py 23. audio_features.py 24. MediaTranscriber.py 25. SearchCommon.py 26. SortEngine.py 27. Shared modules and logging **Part 3 — Tools** 28. orphan_check.py 29. pdf_duplicate_spotter.py and pdf_dupe_review.php 30. audio_features_list.py 31. audio_features2 32. chktranscribe 33. transcribe_pieces.sh 34. cleanISE_Clone **Part 4 — Reference** 35. Interpreters and dependencies 36. Open items and planned work 37. Manual version history --- # Part 1 — Operator guide ## 1. What ISE does ISE adds five search sources to SMF's CustomSearch dropdown: | Source | What it searches | Built by | |---|---|---| | **ISE** | Post bodies and subjects across the whole forum, through ISE's own word index (not SMF's built-in search) | `IndexBuilder.py` | | **ISEpdf** | Text extracted from PDF attachments, plus each PDF's filename and its topic's subject. A result opens the PDF.js viewer at the matching page | `PDFIndexer.py` | | **ISEmisc** | Text attachments. Full content of `.md` `.txt` `.text` `.json` `.html` (HTML reduced to its visible text) and, since MiscIndexer 7.4.1#5, any other flat-text attachment (`.csv`, `.log`, no extension, ...). Code and config types (`.py` `.php` `.js` `.sh` ...) by filename and type only. Also each file's filename and topic subject | `MiscIndexer.py` | | **ISEmega** | The same query run against ISE, ISEpdf and ISEmisc, merged into one page. **It does not include ISEmedia**, despite the name | the three above | | **ISEmedia** | Images, video and audio, by keyword: filename, internal filename, post subject, AI captions of images and video frames, audio tags, and the speech in videos. Audio can also be filtered by tempo and key | `MediaIndexer.py`, `MediaProcessor.py`, `AudioProcessor.py`, `MediaTranscriber.py` | Content is matched against pre-built JSON indexes, not the forum database, so an index only knows what was there when it was last built (§5). Filenames and subjects are a partial exception: `PDFsearch.py` and `MediaSearch.py` look some of them up in the database at search time (§15, §21). ISEmedia loads no AI model at search time. The AI work is done when its stores are built: CLIP (Contrastive Language-Image Pretraining, a model that compares pictures with text) for image vectors, a small vision model for captions, CLAP (its audio counterpart) for audio tags, and a speech model for video transcripts. Re-ordering results with CLIP at search time is an opt-in (`--clip`, §21). ## 2. Where things run | Box | Hostname | Role in ISE | |---|---|---| | **Live** | `forum` (forum.drugs-and-users.org) | The forum and all five searches. Runs the post, PDF and Misc indexers on cron (§5.1), MediaIndexer and MediaProcessor (§5.2) and `MediaTranscriber.py`. 4 GB RAM + 4 GB swap. It had 2 GB until 2026-10-09; some notes in this manual date from then and say so | | **Clone** | `clone` | Runs `AudioProcessor.py` (its audio model needs about 1.6 GB) and pushes the resulting `audio_store.json` to Live. MediaProcessor jobs run there too. Runs `cleanISE_Clone`, which tidies up after them. Clone's `/bin` holds the master copy of the shared `/bin` scripts | | **Dev** | | A mirror of Live. 32-bit, so PDF indexing there uses `PDF-32bit-Indexer.py` (§14) | - **Each SMF instance** (live, smf20, smf21, ...) has its own complete copy of `The_ISE_Project/` and `ISE_Data/`. Nothing is shared between instances. - **The mirror** must carry every `.json` at the root of `ISE_Data` from Live to Clone and Dev, so the stores stay identical for the coherence check. `transcripts_store.json` is written on Live. - **`audio_store.json`** goes the other way: it is built on Clone and pushed to Live. The mirror excludes `ISE_Data/audio_store.json*`, which also covers its lock and temporary files. - **Two Python interpreters** are in use: `python3` (3.6.3 on Live) for the post, PDF and Misc scripts, and `python3.8` for the media, audio and transcript scripts. Details in §35. ## 3. File layout ``` / ├── Sources/Search.php — dispatcher: case 'ISE' / 'ISEpdf' / 'ISEmisc' ├── Sources/ManageSettings.php — CustomSearch_use_ISE / _ISEpdf / _ISEmisc checkboxes, │ plus the ise_reset_pdfjs / ise_reset_isedata reset checkboxes (§9) ├── Sources/Admin.php — registers CustomSearch in the admin menu ├── Themes/default/index.template.php — dropdown options ├── Themes/default/languages/Modifications.english.php — label strings (also patched under │ Themes/default/language/, singular, for installs that use it) ├── Collabware/core_utils.py — settings and attachment lookup for the Collabware scripts (§12) ├── ISE_Data/ — generated indexes, stores and logs (777, apache-owned) │ ├── word_index.json / post_store.json — posts (IndexBuilder.py) │ ├── word_index_pdf.json / pdf_store.json — PDFs (PDFIndexer.py) │ ├── word_index_misc.json / misc_store.json — Misc text attachments (MiscIndexer.py) │ ├── media_store.json — ISEmedia catalogue of images, video and audio (MediaIndexer.py) │ ├── embeddings_store.json — CLIP vectors (MediaProcessor.py); MediaSearch reads it only with --clip │ ├── captions_store.json — captions of images and video frames (MediaProcessor.py) │ ├── audio_store.json — audio tags, vectors, tempo, key, loudness (AudioProcessor.py, built on Clone) │ ├── transcripts_store.json — speech in videos (MediaTranscriber.py, written on Live) │ ├── pdf_duplicates.json / pdf_dupe_deleted.json — duplicate spotter and its review page (§29) │ ├── orphan_state.json — orphan_check.py (§28) │ ├── Settings_ISE.json — per-install {"environment", "install"} selector read by ise_settings.py │ ├── hf_cache/ — Hugging Face model cache (CLIP; and CLAP on Clone) │ ├── ise_trace.log, *.log — shared trace log and per-script logs │ └── lock, checkpoint and status files — listed in each script's section ├── The_ISE_Project/ — all ISE scripts │ ├── qf_search_bridge.php — web entry point for ISE │ ├── qf_PDFsearch_bridge.php — web entry point for ISEpdf │ ├── qf_Miscsearch_bridge.php — web entry point for ISEmisc │ ├── qf_MegaSearch_bridge.php — web entry point for ISEmega │ ├── qf_Mediasearch_bridge.php — web entry point for ISEmedia (the only bridge that resolves python3.8) │ ├── search.py, PDFsearch.py, MiscSearch.py, MegaSearch.py, MediaSearch.py — the five searches │ ├── IndexBuilder.py, PDFIndexer.py, MiscIndexer.py — text indexers │ ├── MediaIndexer.py, MediaProcessor.py, AudioProcessor.py, MediaTranscriber.py — media indexers │ ├── audio_features.py, audio_vocab.txt — used by AudioProcessor.py │ ├── ise_noindex.py — the #do-not-index rule (§6); must sit beside the indexers │ ├── SearchCommon.py, SortEngine.py, ise_settings.py, ise_trace.py — shared modules (§25–27) │ ├── QueryParser.py, Tokeniser.py, ANDMatcher.py, IndexLookup.py, RankingEngine.py, │ │ ResultFormatter.py, ise_render.py — post parsing, scoring and rendering internals │ ├── orphan_check.py, pdf_duplicate_spotter.py, pdf_dupe_review.php — maintenance tools (§28, §29) │ ├── reset_ise_data.php — install-time code hook (§4) │ └── ISE_help.html — shared in-app help page (§8) └── pdfjs/ — bundled PDF.js viewer ``` Tools kept elsewhere: `cleanISE_Clone` in `/bin` on Clone and `transcribe_pieces.sh` in `/root` (§33, §34). Where `audio_features_list.py`, `audio_features2` and `chktranscribe` are installed isn't recorded here (§30–32). ## 4. Installing and uninstalling 1. Install the prerequisite mods first, in this order (see `readme.txt` in the package): **Board-color-and-icons**, **Automatic Package Version Emulation**, **CustomSearch**. 2. Install `ISE_V.zip` through SMF's Package Manager as normal. 3. `install_ise.php` runs by itself. It creates `The_ISE_Project/` and `ISE_Data/` with `777` permissions, then starts `IndexBuilder.py`, `PDFIndexer.py`, `MiscIndexer.py` and `MediaIndexer.py` in the background, so the install itself returns at once. Each writes its own log under `ISE_Data/`. Since v9.5 it also fills `ISE_Data/hf_cache` (the CLIP model cache) if it is empty: copied from root's own Hugging Face cache when installing as root, otherwise downloaded in the background. 4. Go to **Admin > Configuration > Modification Settings > CustomSearch** and untick then re-tick **ISE**, **ISEpdf**, **ISEmisc**, **ISEmega** and **ISEmedia**, saving each time. This makes the dropdown pick up all five. 5. Test a search with each of the five before relying on it. ISEmedia runs under `python3.8`, not the interpreter the other four use, so a working ISE search says nothing about ISEmedia. The model cache matters only for `--clip`. **Uninstalling** reverses the `install.xml` edits and deletes `The_ISE_Project/` only. `ISE_Data/` and `pdfjs/` are deliberately left alone: they hold generated data (indexes, stores, logs, `hf_cache`, the PDF.js viewer) that shouldn't vanish because the mod was removed. ## 5. Building and refreshing the indexes An index only knows what was there when it was last built. Rebuild after posts or attachments change, by hand or from cron. ### 5.1 Posts, PDFs and Misc (Live, `python3`) ```bash cd /The_ISE_Project python3 IndexBuilder.py --monitor # posts → word_index.json / post_store.json python3 PDFIndexer.py --monitor # PDFs → word_index_pdf.json / pdf_store.json python3 MiscIndexer.py --monitor # text attachments → word_index_misc.json / misc_store.json ``` `IndexBuilder.py` and `MiscIndexer.py` rebuild everything on every run, with no resume, so they are safe to re-run at any time. `PDFIndexer.py` resumes by default and only adds PDFs it hasn't indexed yet (§14). Suggested cron (adjust to the forum's posting and upload volume): ``` # Every 2 hours (on the hour) — rebuild the post index 0 */2 * * * python3 /var/www/html/The_ISE_Project/IndexBuilder.py >> /var/www/html/ISE_Data/indexbuilder.log 2>&1 # Every 2 hours (on the half-hour) — rebuild the Misc index 30 */2 * * * python3 /var/www/html/The_ISE_Project/MiscIndexer.py --monitor >> /var/www/html/ISE_Data/misc_indexer.log 2>&1 # Every 6 hours — fast PDF pass (PyMuPDF only) 5 */6 * * * python3 /var/www/html/The_ISE_Project/PDFIndexer.py --fast --monitor >> /var/www/html/ISE_Data/pdfindexer_fast.log 2>&1 # Every 2 days — thorough pass (both extractors) over PDFs not yet indexed. # Resume mode: PDFs already indexed are skipped, so this is NOT a rebuild (that needs --fresh, see §14). 10 0 */2 * * python3 /var/www/html/The_ISE_Project/PDFIndexer.py --monitor >> /var/www/html/ISE_Data/pdfindexer_union.log 2>&1 ``` ### 5.1.1 All three at once: `MegaIndexer.sh` `MegaIndexer.sh` (v1.1.0, ISE 10.8) runs the three indexers above at the same time, shows their output live and reports on each. It keeps the interpreters and options it always used, which differ from the cron lines: | Job | Command | Log in `ISE_Data` (overwritten each run) | |---|---|---| | posts | `python3.8 IndexBuilder.py --monitor` | `megaindexer_posts.log` | | pdf | `python3.15 PDFIndexer.py --fast --monitor` | `megaindexer_pdf.log` | | misc | `python3.8 MiscIndexer.py --monitor` | `megaindexer_misc.log` | ```bash sh /var/www/html/The_ISE_Project/MegaIndexer.sh nohup sh /var/www/html/The_ISE_Project/MegaIndexer.sh > /var/www/html/ISE_Data/megaindexer.log 2>&1 & sh /var/www/html/The_ISE_Project/MegaIndexer.sh --version ``` - **Why parallel is safe:** each indexer writes only its own two files, and all three save through a temporary file renamed into place, so no file is ever half written. - **Live view:** while they run, every line each indexer prints appears on the screen as it happens, labelled `[posts]`, `[pdf]` or `[misc]`. The indexers run with `PYTHONUNBUFFERED=1`, so lines show at once rather than in bursts. Under `nohup` the whole labelled view goes into the output file. - **One run at a time:** the lock `/tmp/megaindexer.lock`. A second run says "Another MegaIndexer run is still going" and starts nothing. - **Priority:** each indexer runs at `nice 10`, so Apache and MySQL come first. - **Result:** at the end, one line per job: OK or FAILED (with the exit code), run time, and the last line of its log. Exit status 0 if all three succeeded, 1 if any failed. Each log begins with a "started" line and ends with `MegaIndexer: exit after s`. - **Ctrl-C or a closed terminal** stops the live view and the report only. The indexers run to the end and keep the lock until they finish. - **Not prevented:** the 2-hourly cron runs of `IndexBuilder.py` and `MiscIndexer.py` can coincide with a MegaIndexer run. Both copies write the same data and the last to finish wins. `PDFIndexer.py` refuses a second copy by its own lock (`/tmp/pdfindexer.lock`) and then shows as FAILED (exit 1). - **Memory:** three indexers in memory at once on Live (4 GB + 4 GB swap). `nice` shares the CPU, not the memory. ### 5.2 Images and video (`python3.8`) 1. `python3.8 MediaIndexer.py` catalogues every image, video and audio attachment into `media_store.json` (§19). 2. `python3.8 MediaProcessor.py --ft=image --progress` (and `--ft=video`) makes CLIP vectors and captions for new items (§20). Mind Live's memory: see §20 before using `--instances`. ### 5.3 Audio (Clone) `AudioProcessor.py` on Clone tags and measures the audio items listed in `media_store.json` and writes `audio_store.json`. Push that file to Live afterwards (§22). ### 5.4 Speech in videos (Live) `python3.8 MediaTranscriber.py` transcribes new `.mp4` videos into `transcripts_store.json`; `chktranscribe` shows how the job is doing (§24, §32). ### 5.5 Housekeeping (Clone) `cleanISE_Clone --apply` clears old temporary files, oversized logs, old checkpoints and stale lock files out of `ISE_Data` (§34). ## 6. The #do-not-index tag A post can be kept out of every ISE index, together with all its attachments, by writing `#do-not-index` in it. One shared module, `ise_noindex.py` (v1.2.0, 2026-10-17), holds the rule and every indexer calls it. It **must sit in the same folder as the indexers**; they refuse to run without it. `python3 ise_noindex.py --version` prints its version. ### 6.1 The rule All three conditions must be true: 1. **The text** `#do-not-index` is in the post **body**, in any letter case. The subject line is never looked at, and neither is the text inside attached files. 2. **It is on lines 1–5 of the body.** SMF stores line breaks as `
`; the count treats `
`, `
`, `
` and plain newlines alike. On line 6 or later it does nothing. Put it on line 1. 3. **The post's author is a Moderator or above:** in the Administrator group (id 1) or the Global Moderator group (id 2), as primary or additional group, or a moderator of that post's own board. Anyone else's tag is ignored. The check is on who *wrote* the post, because SMF doesn't record who typed a tag into it, so a moderator adding the tag to a member's post has no effect. Only group membership by id counts, not what the group is allowed to do. The group ids are constants at the top of `ise_noindex.py`. **Check:** this manual has called them `ADMIN_GROUP` / `GLOBAL_MOD_GROUP`, but an earlier note said `PRIVILEGED_GROUPS`; the file itself decides. If an account in another group must be able to mark posts, add that group's id there or make the account a moderator of the board. What is excluded: the post itself, **every attachment** on it, and the thumbnail record SMF keeps for each image attachment (`id_thumb`). If the tag is removed later, the post and its attachments are indexed again on the next run. ### 6.2 What each indexer does | Script | Since | Behaviour | |---|---|---| | `IndexBuilder.py` (posts) | 7.4.5 | Marked posts are skipped; the summary shows `(+N skipped: #do-not-index)`. Full rebuild every run, so a newly marked post drops out on the next run | | `PDFIndexer.py` | 8.7.0 | Marked PDFs are never discovered, and anything already indexed is **purged** at the start of the run (also with `--fastest`). `--single ID` on a marked attachment prints `REJECTED`, removes any existing entry and exits 1 | | `MiscIndexer.py` | 7.4.1#4 | Attachments of marked posts are left out (catch-all files included); the run prints a skip count. Full rebuild every run | | `MediaIndexer.py` | ISE v9.9.10 | Marked images, video and audio are left out of `media_store.json`. In `--single` mode the rest of the store is kept, but a marked id is **removed** | | `AudioProcessor.py` | 1.3.0 | Marked audio is never encoded; stored items and their windows are removed at the start of every run (also with `--attachid`). `--plan` only reports. Push `audio_store.json` to Live afterwards | | `MediaTranscriber.py` | 1.0.0 | A video in a marked post is never transcribed, and a stored transcript for one is removed | | `MediaSearch.py` | 1.11.0 | A transcript is only shown for an attachment still in `media_store.json`, so one for a newly marked video never surfaces | **Fails closed.** If the list of marked posts can't be read from the database, every indexer stops with exit code 1 and writes nothing. None treats a failed lookup as "nothing is excluded". ### 6.3 What it does not cover - **`MediaProcessor.py`.** Captions and CLIP vectors already made for an image or video that is marked later stay in `captions_store.json` and `embeddings_store.json` until MediaProcessor gets the same purge. MediaSearch (as documented at 1.7.1) takes candidates from `captions_store.json` as well as the catalogue, so such an item may still be found by its caption. - **Filename and subject matching at search time.** `PDFsearch.py` and `MediaSearch.py` look some filenames and subjects up in the database while searching. Whether a marked post's subject or attachment filename can still surface that way has not been confirmed. To test: search for a word from the marked post's subject and from one attachment's filename, as an account that can't see the post. - **Other copies** of the stores: Live's, Clone's and Dev's copies and any backups keep old entries until re-synced or rebuilt. - **Direct attachment URLs** and **SMF's own search** of post text are outside ISE and unaffected. - **A post that merely mentions the tag** on lines 1–5, written by a Moderator or above, is hidden too. It fails safe. ## 7. Searching: words, quotes, wildcards, AND/OR, sorting, result caps The user-facing explanation is in the in-app help (§8). This section is the operator's view. ### 7.1 AND and OR Every source requires every space-separated term by default (AND), as of search.py, PDFsearch.py, MiscSearch.py and MediaSearch.py v7.6.0/7.7.0/7.6.0/1.8.0. Prefix `/sort use-OR` to accept any term instead. An uppercase `AND` typed as a keyword is stripped before searching. This is `SortEngine.extract_or_mode()` (§26), called at the top of every `get_ranked_results()`. ### 7.2 Quotes and punctuation (ISE posts) - **No quotes:** an ordinary word, matched case-insensitively. - **`"double quotes"`:** an exact phrase, matched **case-sensitively**, with spaces and punctuation exactly as typed. - **`'single quotes'`: a known gap.** Single quotes are not treated as a phrase; the word is searched with its apostrophes attached, which almost always finds nothing (§13, §36). - **A word with punctuation in it** (`claude.ai`): matched as that exact string, not as two words. ### 7.3 Names and wildcards (ISEpdf, ISEmisc, ISEmedia) These three share one copy of the matching code, `SearchCommon.py` (§25): - **Names** (filename, internal filename, subject) match case-insensitively. A plain term is a substring. A term with `*` or `?` is matched against the **whole** name, so anchor it with your own `*`: `*.mp3` ends in .mp3, `*sensuous*` contains it, `sensuous*` starts with it. - **Word fields** (content, captions, tags, the word index) match whole words, with wildcards per word. - Per-source differences kept on purpose: ISEmisc's quoted phrases stay case-sensitive; ISEmedia treats `*` and `?` inside quotes as plain text and skips empty names. - A term without `*` or `?` takes the fast exact lookup; only a wildcard term scans the vocabulary. - **ISE (posts) has no wildcards yet** (§36). **Check:** the PDFsearch notes from before SearchCommon described its wildcard matching as case-sensitive, while SearchCommon's rule says names match case-insensitively and PDFsearch 7.8.0 says "no behaviour change". Test a mixed-case filename with a wildcard to see which holds. ### 7.4 Sorting with `/sort` Type the directive in the search box, like `/help`. The older `#ise-order-` form still works; if both appear, `/sort` wins. Parsing happens in Python (`SortEngine.py`, §26), not in the bridges. | Directive | Order | Sources | |---|---|---| | `/sort newest` | `poster_time`, newest first | all five | | `/sort oldest` | `poster_time`, oldest first | all five | | `/sort newmod` | `modified_time` newest first, falling back to `poster_time` for a post never edited | ISE (posts) only | | `/sort oldmod` | the same, oldest first | ISE (posts) only | | `/sort use-OR` | any term instead of every term (§7.1) | all five | - **Why newmod/oldmod are posts-only:** attachments carry `poster_time` only. They aren't edited the way a post is, so the PDF and Misc stores have no `modified_time`. - **ISEmega:** `newest`/`oldest` do a flat date merge across its three sources (`ise_render.merge_by_date()`), not a re-sort of the usual interlaced merge. Interlacing exists to stop one source crowding out the others on score, which doesn't matter when sorting by date. `newmod`/`oldmod` are not offered there; use ISE (posts) directly. - **ISEmedia:** `newest`/`oldest` sort the items that match the query's words. A bare `/sort newest` with no other term lists every item. (In 2026-09 this needed a special gate, because CLIP similarity made every item a candidate; MediaSearch is now keyword-based.) - The "Why is this ranked #N?" explainer on each card names the active sort instead of claiming a relevance ranking. ### 7.5 Result caps | Source | Default | How to see everything | |---|---|---| | ISE, ISEpdf, ISEmisc | No cap through the UI (their bridges pass no `--limit`) | — | | ISEmega | Soft cap of 180 cards (`MEGA_SOFT_CAP`) | "Show all" link (`&all=1`, passed on as `--all`) | | ISEmedia | Soft cap of 180 cards (`MEDIA_SOFT_CAP`), with a red "Showing 180 of N — Show all" notice | The same "Show all" link | Everything is still searched and ranked in full; the cap only limits how many cards are drawn. On the command line, `--limit N` shows exactly the best N. Before bridge v1.1.0, ISEmedia's bridge passed `--limit 180`, which silently cut results off. ## 8. In-app help (`/help`) All five search UIs share one help page, `The_ISE_Project/ISE_help.html`: a single static file, web-accessible through the `.htaccess` `` rule. It explains each source's search methods, including how quoting and wildcards differ between sources and the single-quote gap in ISE posts, stated plainly. It documents ISEmega and ISEmedia too (its ISEmedia section was updated for MediaSearch 1.6.0). Two ways to reach it: - **Type `/help`** as the whole query in any search box (case and surrounding spaces don't matter). Each search script checks for this before searching and copies `ISE_help.html` into the `--html` path the bridge asked for, so the bridge's normal `readfile()` serves it with no PHP changes. On the command line, with no `--html`, the script prints the file's path instead. - **The "❔ How search works" link** at the foot of ISE, ISEpdf and ISEmisc results pages, added to `ResultFormatter.py`'s `format_html()`, `PDFsearch.py`'s `write_html()` and `MiscSearch.py`'s `write_html()`. How it is wired: ```python HELP_TRIGGER = "/help" HELP_HTML_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ISE_help.html") def _serve_help(html_path): with open(HELP_HTML_PATH, "r", encoding="utf-8") as f: content = f.read() if html_path: with open(html_path, "w", encoding="utf-8") as f: f.write(content) return True ``` `search.py`, `PDFsearch.py` and `MiscSearch.py` each define this pair; `MegaSearch.py` reuses `search.py`'s copy and `MediaSearch.py` defines its own. Both paths log through `ise_trace`, and an SSH run starts a new trace as a normal search would. The page carries its own copy of `ResultFormatter.py`'s 13 themes and switcher. On load it reads whichever of `ise_search_theme`, `ise_pdf_theme` and `ise_misc_theme` is set in `localStorage`, so it opens in the theme last picked on a results page. ISEmedia's own theme key is `ise_media_theme`. ## 9. The reset checkboxes Two checkboxes on the CustomSearch settings page set a one-shot reset for the next install or reinstall. Both default to unticked. Each clears itself once it has fired, so it can't wipe again on a later reinstall you didn't mean as a reset. - **"Wipe pdfjs on next reinstall"** deletes and recreates `pdfjs/`. The library is refreshed on every normal install anyway, so this only matters for a genuinely clean slate, which also removes anything that isn't part of the library, such as hand-made `ln` symlinks. Re-create those links afterwards; the checkbox label says so. - **"Wipe ISE_Data on next reinstall"** deletes and recreates `ISE_Data/`, which means **everything in it**: every index and store (posts, PDF, Misc, media catalogue, captions, CLIP vectors, audio, transcripts), `hf_cache`, the duplicate and orphan state files and all logs. Afterwards every index must be rebuilt (§5), `audio_store.json` pushed again from Clone, and every video transcribed again, which takes a long time. ## 10. Known quirks of this SMF fork - **`position="before"` and `position="after"` are inverted** in this fork's Package Manager compared to stock SMF: `before` inserts after the matched text, and the other way round. `install.xml` already allows for this; don't "fix" it back to stock meaning. - **A bare ``/`` with no position attribute silently does nothing**, even though the install preview says "Test successful". Always use `position="before|after|replace"` with ``. - **Python 3.6 decodes subprocess output as strict ASCII by default.** Code that shells out to `pdftotext` or similar must pass `encoding="utf-8", errors="replace"`, or it crashes on accented letters, curly quotes and dashes in real PDFs. This doesn't apply to the `python3.8` scripts, so an encoding problem in one of those is a different problem. - **Repeated small patches to the same block drift.** Several mods (or versions of one mod) each adding ``/`` against the same line leave its whitespace inconsistent over a few install cycles, with array entries and `$txt[...]` lines crammed together. The next mod's search then fails to match ("Skipping Search"). For a settings array or a labelled string block likely to be touched by more than one install, such as the `BIOHAZARD:CustomSearch` block in `Modifications.english.php`, replace the whole known block in one `position="replace"` instead of layering adds. - **`install.xml` (a `` document) may only hold ``/`` blocks.** ``, ``, `` and `` belong in `package-info.xml` only. A stray `` block once found inside `install.xml` was removed. - **`require-dir` merges on install; it never deletes.** A file already in the destination is only overwritten if the package contains a file of exactly that name. So the `ISE_Data/` folder inside any package zip must contain **only** `.htaccess`, never real index, store or log names, or a routine reinstall would overwrite live data with the package's empty copies. `pdfjs/`, by contrast, should contain the full library every time. - **"Package appears to be empty"** on upload isn't necessarily a permissions problem, whatever SMF suggests. Two other causes found on this fork: the `` external reference can fail to resolve (SMF doesn't need it, so it can be dropped), and modern zip tools may write Zip64 or extra-attribute data that this fork's extractor can't read. Build with the legacy zipper, or `zip -X -D` (no extra attributes, no directory entries), which keeps the archive at plain PKZIP 2.0. - **A results page with a fixed filename is a caching trap.** `qf_search_bridge.php` once wrote every search to the same `ISE_results.html`, so browsers could keep showing an old cached page after an update, with no error. It now uses the unique per-request name the other bridges use (`...__.html`). If a results page looks stale after a code update, check whether its bridge writes to a fixed filename before blaming the deployed code. ## 11. Troubleshooting | Symptom | Likely cause | |---|---| | Same results whatever the query | The bridge PHP failed silently and served a stale output file | | A search finds almost nothing on a busy forum | The index wasn't rebuilt after content changed, or an indexer read the wrong instance's `Settings.php` or attachments folder | | One instance's search shows another instance's data | A script has a hard-coded absolute path instead of one relative to its own location. Check `ATTACH_DIR`, `WORD_INDEX_PATH`, `*_STORE_PATH` and the bridge's `$script` | | Dropdown missing ISE options after install | The `index.template.php` operation didn't match. Compare tabs and whitespace with the live file using `cat -A` | | `install_ise.php` runs but nothing happens | `The_ISE_Project` wasn't extracted yet when the code step ran. The code step must come after the extract steps in `package-info.xml` | | A settings checkbox shows with no label | The language-string `` anchor didn't match, usually whitespace. Check the anchor byte for byte against a fresh copy of the live file (`cat -A` or `od -c`) | | Package Manager says "Skipping Search" | The `` text really isn't in the target file. Pull the file off the server and diff it; an anchor that matched for an earlier version may not match now (§10) | | A patch shows as installed but the page hasn't changed | Look at the raw file on the server. If it is patched, suspect PHP OPcache or SMF's cache: restart Apache or call `opcache_reset()`, and clear SMF's cache under Admin > Maintenance | | ISEmega or ISEmedia stops at 180 results | Not a bug: their soft cap. Use "Show all" (§7.5) | | PDF search over SSH prints "ISE ERROR — see ..." for a query with no matches | PDFsearch.py older than 7.5.2 (§15) | | `orphan_check.py` fails at once with `ImportError: cannot import name 'BOARD_URL'` | orphan_check.py older than 7.4.2 (§28) | | `ModuleNotFoundError: No module named 'numpy'` or `'torch'` from a media script | Wrong interpreter: the media scripts need `python3.8`. Over SSH use the full path, `/usr/local/bin/python3.8`; `sudo`'s `secure_path` may not include `/usr/local/bin` | | `PermissionError: [Errno 13] ... /.cache` from MediaSearch with `--clip` | The model cache isn't reachable by apache. Check that `ISE_Data/hf_cache/hub/models--timm--vit_base_patch32_clip_224.openai` exists and is owned by `apache:apache`, and read `ISE_Data/hf_cache_setup_status.log` | | An ISEmedia result with no visible link to the query | Every card shows its `match_evidence` (term, field, value). Before 1.2.0, MediaSearch ranked by CLIP similarity alone and could show unrelated items; such a result means an old MediaSearch.py | | A deleted audio attachment shows in ISEmedia as "No topic found" | Its entry is still in `audio_store.json`. Run `AudioProcessor.py --prune` on Clone, then push the store (§22) | | `[!] No frame from ID n` with `duration 60.0` | ffprobe is missing or failed, so MediaProcessor sampled past the end of a short clip (§20) | | `AudioProcessor` says "FATAL: this host is 'forum'" | It runs on Clone by default. Add `--any-host`, or `--force` (from 1.3.1), to run it elsewhere (§22) | | A second run says it is already running | AudioProcessor and MediaTranscriber allow one run at a time. Check with `pgrep -fl ` and wait (§22, §24) | | The `#do-not-index` tag is ignored | The tag is below line 5, or the author isn't a Moderator or above, or the author's group id isn't one `ise_noindex.py` knows (§6) | --- # Part 2 — Script reference ## 12. Two codebases, two settings mechanisms ISE's scripts come from two codebases joined into one project. Knowing which one a script belongs to saves chasing a settings or version problem in the wrong place. | | ISE scripts | Collabware scripts | |---|---|---| | **Which** | `search.py`, `PDFsearch.py`, `MiscSearch.py`, `MegaSearch.py`, `MediaSearch.py`, `IndexBuilder.py`, `PDFIndexer.py`, `MiscIndexer.py` | `MediaIndexer.py`, `MediaProcessor.py` (a four-way effort: Andrew, Claude, ChatGPT, Gemini). `AudioProcessor.py` also uses Collabware's helpers | | **Board URL and paths** | `ise_settings.py`: `get_base_url()` / `get_project_url()` read the per-install `ISE_Data/Settings_ISE.json` (`{"environment": ..., "install": ...}`) and look the URL up in a hand-checked table | `Collabware.core_utils`: `get_board_root()`, `get_data_dir()`, `load_smf_settings()`, `locate_attachment_file()`, `get_attachment_directories()` | | **Version numbers** | Per file: `search.py` 7.x, `MediaSearch.py` 1.x, and so on | A project-style tag in the doc-block ("ISE v9.9.10", "ISE v9.25") plus a `RUNTIME_VERSION` string kept in step by hand. Not the same counter as the package's own version (`install_ise.php` "9.5"). `AudioProcessor.py` uses its own per-file number | | **Logging** | `ise_trace.py` (§27) | Their own `--monitor` / `--verbose` output | - **Database credentials** come from SMF's `Settings.php` for every script. There is no separate config file and no hard-coded credentials. - **`ISE_ROOT`**: some bridges still set it as an environment variable, but no current Python reads it back. Earlier manuals said settings came "from `Settings.php` via `ISE_ROOT`"; that stopped being true with `ise_settings.py` v4.0 (2026-08-21); 4.0/4.1 brought in `Settings_ISE.json`. - A settings error in a Collabware script is not an `ise_settings.py` / `Settings_ISE.json` problem, and an "ISE v9.x" tag is not the package version. ## 13. IndexBuilder.py and search.py (posts) ### IndexBuilder.py **Version:** 7.4.5 (2026-10-17). `python3`. Builds `ISE_Data/word_index.json` and `ISE_Data/post_store.json` from every forum post. Every run is a full rebuild, so it is safe to run at any time; usage and cron are in §5.1. Since 7.4.5, posts marked `#do-not-index` are skipped and the summary ends with `(+N skipped: #do-not-index)` (§6). ### search.py Searches the post index. A query goes through `QueryParser.parse()` → `Tokeniser.tokenise()` → `ANDMatcher.match()` → `IndexLookup.py`'s `lookup_word()` / `lookup_phrase()`: - **No quotes:** a normal `WORD` token, lowercased and looked up directly in `word_index.json` (the fast path) if it is a plain `\w+` string. - **`"double quotes"`:** a real `PHRASE` token, matched by `lookup_phrase()` as an exact, case-sensitive, literal substring of the raw post text (`phrase in post["text"]`). - **`'single quotes'`:** not special-cased anywhere. `QueryParser.py`'s regex only recognises `"..."`, so a single-quoted word is caught by the generic `\S+` pattern with its quotes. `Tokeniser.py`'s docstring says WORD terms have punctuation stripped, but the code only lowercases. So `'test'` stays the literal token `'test'`, which isn't `\w+`, and `lookup_word()` falls back to a case-insensitive literal substring search for `'test'`, apostrophes included. That almost never matches. A confirmed gap, not a design choice (§36). - **A word with other punctuation** (`claude.ai`): the same fallback, a case-insensitive literal substring match, not `claude` and `ai` as separate words. Sort modes accepted (`ORDER_KEYS`): `relevance`, `score`, `date` (an old alias for `newest`), `newest`, `oldest`, `newmod`, `oldmod`, `subject`, `board`, `author`, `occurrences`. The directive is parsed inside `get_ranked_results()` itself, so MegaSearch's direct call gets it too; before that, a `/sort` routed through ISEmega leaked into the query as search words. `newmod`/`oldmod` fall back to `poster_time` for a post never edited (`_effective_modified()`). SSH runs write the query to syslog themselves (§27). `/help` is handled as in §8. ## 14. PDFIndexer.py **Version:** 8.7.0 (2026-10-17). `python3`. Builds the PDF index. It finds every real PDF attachment on disk by magic bytes (the database's stored extension can be wrong), extracts the text of each page and writes: - `ISE_Data/word_index_pdf.json`: word → list of `[id_attach, page]` hits - `ISE_Data/pdf_store.json`: `id_attach` → `{filename, pages}` ### Extraction engines Two independent extractors run on every page, and the index takes the union of the words they find: - **PyMuPDF (fitz):** fast, and copes well with malformed PDFs. - **pypdf**, pinned to `3.1.0`: later versions need Python 3.8+ and crash on this box's 3.6. Tried and rejected: **pdfplumber** (its dependencies need `cryptography` compiled, which needs a Rust toolchain this CentOS 6 box doesn't have) and **pypdfium2** (no wheel for this platform at any version). ### Usage ```bash python3 PDFIndexer.py --monitor # thorough (both engines); resumes if re-run python3 PDFIndexer.py --fast --monitor # PyMuPDF only python3 PDFIndexer.py --fresh --monitor # full rebuild, ignoring what's indexed python3 PDFIndexer.py --start-at 5235 --monitor # restart a killed run from a known id python3 PDFIndexer.py --limit 5 --dry-run --monitor # test without writing python3 PDFIndexer.py --single 6474 --fast # index and trace one attachment, then exit ``` ### Options | Flag | Default | Description | |---|---|---| | `--attach-dir DIR` | auto (`/attachments`) | Folder to scan for PDF attachments | | `--dry-run` | off | Discover and extract only; write nothing | | `--limit N` | none | Process only the first N PDFs found (for testing) | | `--monitor` | off | Live progress: which engine is running per file, new words per file, and a summary every 5% | | `--verbose` | off | Also send log output to stdout, not just the log file | | `--fresh` | off | Ignore the existing index and rebuild everything. Without it the run **resumes**: it loads the index and skips attachments already indexed | | `--checkpoint-every N` | `25` | Save progress every N PDFs, so a crash (for example an out-of-memory kill) loses only recent work. `0` saves once at the end | | `--start-at ID_ATTACH` | none | Skip every attachment below this id, to restart from a known point | | `--fast` | off | PyMuPDF only, skipping pypdf. About 20 times faster per file and lighter on memory, but loses pypdf's extra coverage | | `--fastest` | off | Skips attachment ids already in the index. Its full behaviour isn't recorded here; see `--help`. Refused with `--single` | | `--single ID_ATTACH` | none | Index that one attachment and exit (8.6.1). It is checked with `file(1)` first: if it isn't a PDF, or no file with that id exists, the run prints `REJECTED`, exits 1, loads no index and writes nothing. If it is a PDF, it is re-processed even if already indexed and merged into the stores; no other attachment is touched. Prints `--single N:` trace lines ending with a `RESULT` line. Refused with `--fresh` or `--fastest` | ### Notes - **#do-not-index (8.7.0):** attachments of a marked post are never indexed, and existing entries are purged at the start of the run (§6). Needs `ise_noindex.py` in the same folder. - **Memory:** the full two-engine index is held in memory during a run. When Live had 2 GB, a full pass was seen to trigger the out-of-memory killer near its end. `--checkpoint-every` limits what such a kill loses, and `--fast` cuts peak memory a lot. Watch `free -h` during a full `--monitor` run if concerned. - **Tokeniser:** a regex tokeniser (`tokenise()` in the script) since 7.4, not a plain `.split()`. - **Page numbers after a blank page:** a page that follows a blank page can be recorded one number too low, so its hits point one page early. Entries already indexed keep the wrong number until a `--fresh` rebuild, because the default resume skips them. - **Filenames:** `pdf_store.json`'s `filename` field is always `None`. `resolve_filename()` exists but isn't called from `main()`. `PDFsearch.py` gets real filenames from the database itself, so search isn't affected (§36). ### PDF-32bit-Indexer.py (Dev) **Version:** 8.6.0 (2026-10-05). The 32-bit edition, rebuilt from PDFIndexer.py 8.6.0 (it replaced the old 32-bit 8.2.3). Same options as 8.6.0, including `--single` and `--fastest`. Differences: - needs a 32-bit system; - runs PyMuPDF in a child process with a 30-second limit (kept from 8.2.3); a failed or timed-out child skips the file; - works with both PyMuPDF spellings, `get_text()` and `getText()`. Dev's 32-bit builds (1.11.2 and 1.14.21) only have `getText()`, which made 8.2.3's PyMuPDF pass fail on every file; - its start-up line reads `PDF-32bit-Indexer.py v8.6.0`. On Dev it writes Dev's own `pdf_store.json` / `word_index_pdf.json` unless run with `--dry-run`. It was built from 8.6.0, so unless it has been rebuilt since, it has neither 8.6.1's run-one-and-exit `--single` nor 8.7.0's `#do-not-index`. ### Version history - **8.7.0 (2026-10-17):** `#do-not-index`; marked PDFs purged at the start of each run. - **8.6.1 (2026-10-07):** `--single` means "run that one and exit". In 8.6.0 it printed its trace and then carried on into the full discovery sweep. - **8.6.0 (2026-10-01):** `--single ID_ATTACH` added. ## 15. PDFsearch.py **Version:** 7.8.0 (2026-10-06). `python3`. Searches the index PDFIndexer builds, and also checks every PDF attachment's own filename and its topic's subject, so a document titled with the right words is found even when the words never appear in its extracted text. ### Usage ```bash python3 PDFsearch.py listatt # console, every match python3 PDFsearch.py heroin --limit 20 # capped, for a quick SSH check python3 PDFsearch.py heroin --html /var/www/html/ISE_Data/results.html ``` The query is taken from `argv[0]` before argparse sees it (7.5.1), so a search starting with `-` or `--` is searched rather than rejected as an unknown option. The query must therefore come first. | Flag | Default | Description | |---|---|---| | `--limit N` | none (no cap) | Cap the number of results | | `--html FILE` | none | Write an HTML results page to this path | | `--source {ui,ssh}` | `ssh` | Accepts the `--source=ui` the bridge passes. `ise_trace.py` works out UI or SSH itself from `sys.argv` | ### What a result can look like - **Content match:** the term is in the extracted text. Shows the matching page numbers and a link that opens the PDF there. - **Title or topic match only:** the term is in the filename or the topic subject but not the text. Still shown, never hidden, with a "🔎 Matched via title/topic" block naming the term, field and value. - **Both:** page hits and a title/topic match, shown together. - **Orphaned attachment:** if the attachment's `id_msg` no longer resolves to a post, the result shows "No topic found" instead of an Open PDF link. SMF's `dlattach` needs a valid topic to serve the file, and there is no working fallback. ### Matching Query words are matched exactly against `word_index_pdf.json`. Since 7.8.0 the wildcard test, the vocabulary wildcard and the filename/subject match come from `SearchCommon.py` (§7.3, §25), with no change in behaviour; `tokenise()` stays local because it mirrors this script's own index. A term without `*` or `?` keeps the fast exact path; only a wildcard term scans the whole vocabulary. ### syslog UI searches are written to syslog by `qf_PDFsearch_bridge.php` before the script runs. SSH runs bypass the bridge, so the script logs the query itself (tag `ise-pdf-search-ssh`, message prefixed `[SSH]`). Both paths end up in syslog. ### Version history - **7.8.0 (2026-10-06):** wildcard test, vocabulary wildcard and filename/subject match taken from `SearchCommon.py`. No behaviour change. - **7.5.2 (2026-09-23):** a search with no matches returned a bare `[]` instead of the `(results, order_mode)` pair every caller unpacks. Over SSH that printed "ISE ERROR — see ..." instead of "No matches."; through the bridge it was invisible; through MegaSearch it was logged as "pdf source failed". Now returns `[], order_mode`. - **7.5.1:** query taken from `argv[0]` before argparse. ## 16. MiscIndexer.py **Version:** 7.4.1#5 (2026-10-17). `python3`. Builds the index for text attachments. Simpler than PDFIndexer: the files are already text, so there is no extraction step, no second engine and no resume. Every run is a full rebuild. - **Full content** of `.md`, `.txt`, `.text`, `.json` and `.html` is read, tokenised and indexed. `.html` first goes through `strip_html_for_indexing()`: `