web_search_helper.site module

Put the engine into a website folder, run it locally, check it online.

install copies search.php, web-search.js (and its .d.ts) and the index files into a site folder, under search-data/ with a .htaccess that denies everything. The index files do not need it (requested by URL, they answer 404), but two locks are better than one.

check_online is to run AFTER uploading: it fetches the index files the way a visitor would and fails if any byte of the corpus comes back; it then asks the endpoint one question. An upload fails silently (a client that skips dotfiles, a file left halfway); the page still displays.

web_search_helper.site.asset(name)[source]
Parameters:

name (str)

Return type:

Path

web_search_helper.site.bench(index, runs=5, question='test question', php='php')[source]

Time the PHP engine on an index: load, then full searches (words + meaning).

The search is exhaustive (every window is compared with the question). ann-router would pick HNSW from 1 000 vectors under a 10 ms budget, but its thresholds are measured on numpy, not PHP, and the “I cannot answer” rule judges the ABSOLUTE best cosine, which an approximate index may miss. So the exhaustive scan stays as long as this measure fits the budget.

Parameters:
Return type:

dict

web_search_helper.site.check_online(base_url, langs, question='test', data_dir='search-data')[source]

Is the corpus private, and does the endpoint answer?

Parameters:
Return type:

dict

web_search_helper.site.install(site, indexes, data_dir='search-data', demo=False)[source]

Copy the endpoint, the client and the index files into site.

demo also copies the bilingual demo page as demo.html.

Parameters:
Return type:

list[Path]

web_search_helper.site.serve(site, port=8765, php='php')[source]

php -S on site: the local twin of the hosting.

Parameters:
Return type:

Popen