fix: rank a console first for its own name

The PlayStation 2 page holds every word of "playstation bios" and pagefind ignores the words a page has that the query lacks, so its own body matches put it first. A console whose every word another system page's consoles also hold is now written again in an `exact` field (weight 20). File names reach the `files` field as their parts: whole names let "ds" reach twelve dsi_* names on the DSi page. `consoles` weighs 100 so an emulator named after its console (Saturn.emu) comes second, and `aliases` 10 so the Nintendo page keeps "gba bios". The gate runs both directions of the PlayStation, Game Boy, DS and Wii pairs and Saturn.
This commit is contained in:
Abdessamad Derraz committed 2026-10-27 06:54:08 +01:00
1 parent 6a611cd77a
commit 07f785cfd7
9 files changed
+191 -25

No files matched your search

+2 -2
View File
@@ -291,8 +291,8 @@ class SearchFoldsPagesUnderAHash(unittest.TestCase):
def test_search_fields_are_weighted_and_never_shown(self):
config = _read(CONFIG)
self.assertIn("metaWeights: { title: 10, files: 0.5, aliases: 5, devices: 5, consoles: 10, terms: 30 },", config)
self.assertIn("const UNSHOWN_FIELDS = new Set(['files', 'aliases', 'devices', 'consoles', 'terms']);", _read(SITE_TS))
self.assertIn("metaWeights: { title: 10, files: 0.5, aliases: 10, devices: 5, consoles: 100, exact: 20, terms: 30 },", config)
self.assertIn("const UNSHOWN_FIELDS = new Set(['files', 'aliases', 'devices', 'consoles', 'exact', 'terms']);", _read(SITE_TS))
class OsTabsNeverScrollThePage(unittest.TestCase):
+2 -1
View File
@@ -65,7 +65,8 @@ class MetaFields(unittest.TestCase):
body = ('<h3 class="rb-file-title"><code>scph5501.bin</code></h3>'
'<h3 class="rb-file-title"><code>a,b.bin</code></h3>')
meta = sitestarlight.file_names_meta(body)
self.assertIn('data-pagefind-meta="files:a b.bin scph5501.bin"', meta)
# Each name as its parts, each part once (round 5, 3.2).
self.assertIn('data-pagefind-meta="files:a b bin scph5501"', meta)
self.assertRegex(meta, r"<span [^>]*hidden></span>")
def test_a_field_escapes_its_value(self) -> None:
+2 -2
View File
@@ -214,8 +214,8 @@ class SearchFields(unittest.TestCase):
def test_declared_and_never_shown(self):
config = _read(CONFIG)
self.assertIn("metaWeights: { title: 10, files: 0.5, aliases: 5, devices: 5, consoles: 10, terms: 30 },", config)
self.assertIn("const UNSHOWN_FIELDS = new Set(['files', 'aliases', 'devices', 'consoles', 'terms']);", _read(SITE_TS))
self.assertIn("metaWeights: { title: 10, files: 0.5, aliases: 10, devices: 5, consoles: 100, exact: 20, terms: 30 },", config)
self.assertIn("const UNSHOWN_FIELDS = new Set(['files', 'aliases', 'devices', 'consoles', 'exact', 'terms']);", _read(SITE_TS))
class SearchLoadsOnFirstUse(unittest.TestCase):
+87
View File
@@ -100,6 +100,83 @@ class ConsoleWordsReachTheConsole(unittest.TestCase):
self.assertEqual(typed, set())
class ANameAnotherPageCovers(unittest.TestCase):
"""3.2: the PlayStation 2 page holds every word of "playstation bios".
A console whose words another page's consoles also hold is written once
more, in `exact`, on its own page, and file names reach the search as
their parts: "ds" found twelve dsi_* names on the DSi page."""
PAGES = {
"systems/sony-playstation": ["PlayStation"],
"systems/sony-playstation-2": ["PlayStation 2"],
"systems/sony": ["PlayStation 3", "PlayStation Portable"],
"systems/nintendo-nintendo-ds": ["Nintendo DS"],
"systems/nintendo-nintendo-dsi": ["Nintendo DSi"],
"systems/nintendo": ["Famicom Disk System", "Nintendo 64", "Super Famicom Box"],
"systems/arcade-nintendo-super-system": ["Nintendo Super System"],
"systems/sega-saturn": ["Saturn"],
}
def words(self) -> dict[str, set[str]]:
return {page: sitestarlight.page_console_words({"consoles": names}, "")
for page, names in self.PAGES.items()}
def test_names_another_page_covers(self):
covered = {page: sitestarlight.covered_names(names, page, self.words())
for page, names in self.PAGES.items()}
self.assertEqual(covered, {
"systems/sony-playstation": ["PlayStation"],
"systems/sony-playstation-2": [],
# Every word of PlayStation 3 is on the PlayStation 2 page, but
# not "3" itself: no page covers it.
"systems/sony": [],
"systems/nintendo-nintendo-ds": ["Nintendo DS"],
"systems/nintendo-nintendo-dsi": [],
"systems/nintendo": [],
# Nintendo, Super and System, each in another name.
"systems/arcade-nintendo-super-system": ["Nintendo Super System"],
"systems/sega-saturn": [],
})
def test_words_of_a_decorated_page(self):
text = '<span data-pagefind-meta="consoles:Nintendo DS" hidden></span>'
self.assertEqual(sitestarlight.page_console_words({}, text), {"nintendo", "ds"})
self.assertEqual(sitestarlight.page_console_words({}, "No field."), set())
def test_the_exact_field_is_written_on_the_covered_page_only(self):
words = self.words()
def text(page: str) -> str:
return sitestarlight.finalize_page(
f"{page}.md", "# T\n\nBody.\n", level="0", weight=None,
browser_title="T", description="d", structured={"@type": "TechArticle"},
terms={}, authored={"consoles": self.PAGES[page]}, words_by_page=words)[1]
self.assertIn('data-pagefind-meta="exact:PlayStation"', text("systems/sony-playstation"))
for page in ("systems/sony-playstation-2", "systems/sega-saturn"):
with self.subTest(page=page):
self.assertNotIn('data-pagefind-meta="exact:', text(page))
def test_the_field_is_weighted_and_never_shown(self):
config = (REPO_ROOT / "website" / "astro.config.mjs").read_text(encoding="utf-8")
weights = re.search(r"metaWeights: \{([^}]*)\}", config)[1]
fields = dict(re.findall(r"(\w+): ([\d.]+)", weights))
self.assertIn("exact", fields)
# Below the console field, so the longer name keeps its own query.
self.assertLess(float(fields["exact"]), float(fields["consoles"]))
site = (REPO_ROOT / "website" / "src" / "scripts" / "site.ts").read_text(encoding="utf-8")
self.assertRegex(site, r"UNSHOWN_FIELDS = new Set\(\[[^\]]*'exact'")
def test_file_names_as_parts(self):
body = "".join(f'<h3 class="rb-file-title"><code>{name}</code></h3>'
for name in ("dsi_bios7.bin", "DSi_Nand_USA.bin", "NDS_Bios7.bin"))
meta = sitestarlight.file_names_meta(body)
self.assertIn('data-pagefind-meta="files:DSi Nand USA bin NDS Bios7"', meta)
# A letter of any script is a letter.
self.assertIn("ファミコン", sitestarlight.file_names_meta(
'<h3 class="rb-file-title"><code>ファミコン_bios.rom</code></h3>'))
class GateQueries(unittest.TestCase):
"""3.2, 3.3 and 3.6: the queries the gate runs, the pages that answer
them and the rank they must reach."""
@@ -110,6 +187,16 @@ class GateQueries(unittest.TestCase):
"gamecube bios": (("systems/nintendo-gamecube/",), 1),
"game boy bios": (("systems/nintendo-game-boy/",), 1),
"3ds bios": (("systems/nintendo-3ds/",), 1),
"playstation bios": (("systems/sony-playstation/",), 1),
"playstation 2 bios": (("systems/sony-playstation-2/",), 1),
"playstation 3 bios": (("systems/sony/",), 1),
"game boy advance bios": (("systems/nintendo/",), 1),
"game boy color bios": (("systems/nintendo/",), 1),
"nintendo ds bios": (("systems/nintendo-nintendo-ds/",), 1),
"nintendo dsi bios": (("systems/nintendo-nintendo-dsi/",), 1),
"wii bios": (("systems/nintendo/",), 1),
"wii u bios": (("systems/nintendo-wii-u/",), 1),
"saturn bios": (("systems/sega-saturn/",), 1),
"check my bios folder": (("wiki/troubleshooting/",), 3),
"is my bios correct": (("files/",), 3),
"schema": (("data/",), 3),