Skip to content

Fix: Ignore query strings and fragments in path depth scoring - #2444

Open
LimbC-C wants to merge 1 commit into
unclecode:developfrom
LimbC-C:fix/path-depth-url-suffixes
Open

LimbC-C wants to merge 1 commit into
unclecode:developfrom
LimbC-C:fix/path-depth-url-suffixes

Conversation

@LimbC-C

@LimbC-C LimbC-C commented Oct 25, 2026

Copy link
Copy Markdown

Summary

Fixes #2443.

PathDepthScorer counts slashes in query strings and fragments as path levels. With optimal depth 2, /docs/guide?next=/a/b/c scores 0.25 instead of 1.0, which can change deep-crawl priority. A URL without a path can also pick up a slash inside a query parameter.

Remove literal query/fragment suffixes before locating and counting the path. Preserve weighting, caching, repeated/trailing slash handling and encoded path characters.

List of files changed and why

  • crawl4ai/deep_crawling/scorers.py: one behavioral line strips URL suffixes; scoped Black formatting also removes whitespace-only lines in the affected class and adds the missing final newline.
  • tests/unit/test_path_depth_scorer.py: 12 assertion cases cover suffixes, pathless URLs, encoded separators, weights and repeated calls.

How Has This Been Tested?

  • On unchanged develop: 7 cases fail and 5 controls pass.
  • After the fix: all 12 new assertion cases pass. The existing general scorer diagnostic also reports all scorer/composite checks passed (13 pytest cases total).
  • Black on the new test and the changed source line, Ruff on the new test, and git diff --check pass.
  • Real editable checkout, Python 3.12.14, pytest 9.1.1. No browser/network mocks. Full suite, browser crawling and model tests were not run.

Checklist

  • Added regression tests and ran the focused checks listed above.
  • Human self-review: this patch and its tests were prepared and reviewed with Codex; no human review is claimed.
  • Documentation: no API or configuration change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant