Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/search-core/src/grogbot_search/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,8 @@ def create_documents_from_sitemap(self, sitemap_url: str, bootstrap: bool = Fals
documents: List[Document] = []
for page_url in unique_urls:
canonical_url = _canonicalize_url(page_url)
if "/shop/" in urlparse(canonical_url).path:
continue
if bootstrap:
existing = self.connection.execute(
"SELECT 1 FROM documents WHERE canonical_url = ? LIMIT 1",
Expand Down
22 changes: 22 additions & 0 deletions packages/search-core/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ def log_message(self, format, *args): # noqa: A003 - match base signature
</html>
"""

responses["/shop/product"] = f"""
<html>
<head>
<title>Shop Product</title>
<link rel="canonical" href="{base_url}/shop/product" />
</head>
<body>
<article>
<h1>Shop Product Heading</h1>
<p>Shop product details.</p>
</article>
</body>
</html>
"""

responses["/article-no-canonical"] = """
<html>
<head>
Expand Down Expand Up @@ -360,6 +375,13 @@ def log_message(self, format, *args): # noqa: A003 - match base signature
</urlset>
"""

responses["/sitemap-shop-skip.xml"] = f"""<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>{base_url}/shop/product</loc></url>
<url><loc>{base_url}/article</loc></url>
</urlset>
"""

responses["/invalid-sitemap.xml"] = "<urlset><url><loc>"

responses["/sitemap-bootstrap-skip.xml"] = f"""<?xml version="1.0" encoding="UTF-8"?>
Expand Down
7 changes: 7 additions & 0 deletions packages/search-core/tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,13 @@ def test_create_documents_from_sitemap_deduplicates_urls(service: SearchService,
assert documents[0].canonical_url == f"{http_server}/canonical"


def test_create_documents_from_sitemap_skips_shop_paths(service: SearchService, http_server):
documents = service.create_documents_from_sitemap(f"{http_server}/sitemap-shop-skip.xml")

assert len(documents) == 1
assert documents[0].canonical_url == f"{http_server}/canonical"


def test_create_documents_from_sitemap_invalid_xml_raises_value_error(service: SearchService, http_server):
with pytest.raises(ValueError, match="Invalid sitemap XML"):
service.create_documents_from_sitemap(f"{http_server}/invalid-sitemap.xml")
Expand Down