Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

Wrap HN query terms in double quotes to prevent prefix matching

Daoud Clarke56f0096a797e
diff --git a/mwmbl/tinysearchengine/super_search_sources/hn.py b/mwmbl/tinysearchengine/super_search_sources/hn.py
index 867075a..63cde40 100644
--- a/mwmbl/tinysearchengine/super_search_sources/hn.py
+++ b/mwmbl/tinysearchengine/super_search_sources/hn.py
@@ -13,9 +13,10 @@ ENDPOINT = "https://hn.algolia.com/api/v1/search"
async def search(client: httpx.AsyncClient, query: str, limit: int) -> list[Document]:
try:
+ quoted_query = " ".join(f'"{term}"' for term in query.split())
response = await client.get(
ENDPOINT,
- params={"query": query, "hitsPerPage": limit, "tags": "story"},
+ params={"query": quoted_query, "hitsPerPage": limit, "tags": "story"},
)
response.raise_for_status()
payload = response.json()