An open source, non-profit web search engine
Stop the crawler's indexing loop dying on terms holding an ellipsis
Daoud Clarke6bd7c632a237
diff --git a/mwmbl/crawl.py b/mwmbl/crawl.pyindex 6803be1..553d456 100644--- a/mwmbl/crawl.py+++ b/mwmbl/crawl.py@@ -47,7 +47,6 @@ from mwmbl.rankeval.evaluation.remote_index import RemoteIndexfrom mwmbl.redis_url_queue import RedisURLQueuefrom mwmbl.tinysearchengine.indexer import Document, TinyIndexfrom mwmbl.tinysearchengine.rank import score_result-from mwmbl.tokenizer import tokenizeBATCH_QUEUE_KEY = "batch-queue"REMOTE_SERVER = "https://api.mwmbl.org"@@ -102,8 +101,16 @@ def count_new_index_entries(term: str, new_items: list[Document], remote_items:terms that hash to it, which we cannot see, so the real capacity is lower thanlen(remote_items) suggests and blacklisting can drop items server-side. run_indexing logsthe estimate next to the number the index actually kept, which is how to calibrate it.++ The term is split, not tokenized, which is what the server does to rank a term's+ documents (index_batches.sort_documents) and the only thing that works here: tokenize is+ not a total function on its own output. Index terms come from tokenizing a title, a URL+ or an extract, and one of those can hold an ellipsis mid-text - "Hello… World" gives+ the token "hello…", which tokenize() then reads as a truncated extract and drops the+ last two tokens of, returning []. score_result asserts on an empty term list, so+ re-tokenizing crashed the indexing loop on every batch that carried such a term."""- terms = tokenize(term)+ terms = term.split()new_scores = [score_result(terms, item, True) for item in new_items]matching_new_scores = [score for score in new_scores if score > 0.0]if not remote_items:diff --git a/test/test_crawl_promotion.py b/test/test_crawl_promotion.pyindex 2931c9e..675a6aa 100644--- a/test/test_crawl_promotion.py+++ b/test/test_crawl_promotion.py@@ -194,3 +194,18 @@ def test_run_indexing_submits_the_whole_term_once_the_gate_opens(fake_redis):post.assert_called_once()submitted_urls = {result["url"] for result in post.call_args.kwargs["json"]["results"]}assert submitted_urls == {STRONG.url, WEAK.url}+++def test_a_term_holding_an_ellipsis_is_still_scored():+ """Index terms are not safe to re-tokenize.++ tokenize() treats anything ending in "…" as a truncated extract and drops its last two+ tokens, so the term "python…" - which a title like "Learn python… fast" puts in the+ index - tokenizes to nothing. score_result asserts the term list is non-empty, so the+ crawler's indexing loop died on every batch carrying such a term. Splitting the term is+ what the server does on the way in (index_batches.sort_documents), and it is total.+ """+ ellipsis_term = "python…"+ assert tokenize(ellipsis_term) == []+ assert count_new_index_entries(ellipsis_term, [MEDIUM], []) == 0+ assert count_new_index_entries("learn python…", [MEDIUM], []) == 0