crawl4ai icon indicating copy to clipboard operation
crawl4ai copied to clipboard

[Bug]: PathDepthScorer counts query and fragment slashes as path levels

Open LimbC-C opened this issue 1 month ago • 1 comments

crawl4ai version

0.9.5, current develop at 240d9cd050b26607355a3bcf977aa73660069590.

Expected Behavior

PathDepthScorer should measure the URL path. Adding query parameters or a fragment should not change the path-depth score, even when those suffixes contain slashes or another URL.

Current Behavior

The scorer locates the first slash after the scheme and counts the entire remaining string, including query/fragment text. With optimal_depth=2, /docs/guide scores 1.0 but /docs/guide?next=/a/b/c scores 0.25. An authority-only URL whose query contains another URL can also be scored as if it had a path. This changes the priority assigned to links during deep crawling.

Reproduction

from crawl4ai.deep_crawling.scorers import PathDepthScorer

scorer = PathDepthScorer(optimal_depth=2)
print(scorer.score("https://example.com/docs/guide"))
print(scorer.score("https://example.com/docs/guide?next=/a/b/c"))
# Expected: 1.0, 1.0. Actual: 1.0, 0.25.

The real public scorer reproduced seven failing regression cases and five passing controls on unmodified develop. Query-only, fragment-only, combined suffixes, and a query URL without a preceding path are affected. Root/path controls, encoded characters and repeated separators are covered.

Proposed Fix

Discard the literal query and fragment suffixes before the existing path lookup. Keep the current depth algorithm, weighting, statistics and caches. This is separate from #2405 (file-extension scoring) and the old queue-direction problem #1080/#1081.

Environment

Windows / Python 3.12.14. Pure local scorer calls, with the installed dependencies and actual current checkout import. No browser, external website, model or network request is needed for the reproduction.

AI assistance: Codex identified this during a source audit for contribution opportunities, ran the original-code reproduction and prepared the minimal repair. No human review is claimed.

LimbC-C avatar Oct 25 '26 01:10 LimbC-C

Closing this duplicate report because the earlier #2302 already contains the corresponding fix; duplicate PR #2444 has been closed.

LimbC-C avatar Oct 26 '26 01:10 LimbC-C