Skip to content

fix(deep-crawl): FreshnessScorer defaults to the current year - #2427

Open
Siddharth-DWT wants to merge 1 commit into
unclecode:developfrom
Siddharth-DWT:fix/freshness-scorer-current-year
Open

Siddharth-DWT wants to merge 1 commit into
unclecode:developfrom
Siddharth-DWT:fix/freshness-scorer-current-year

Conversation

@Siddharth-DWT

Copy link
Copy Markdown

Summary

FreshnessScorer defaulted to current_year=2024, and _extract_year discards years after current_year as invalid, so from 2025 on a URL dated this year scored 0.5 (the same as an undated URL) while 2024 content scored highest. The default is now None, meaning date.today().year. An explicit current_year works as before.

Fixes #2426

List of files changed and why

  • crawl4ai/deep_crawling/scorers.py: current_year: Optional[int] = None, resolved to the current year in __init__; docstring updated.
  • tests/deep_crawling/test_freshness_scorer_current_year.py: new.

How Has This Been Tested?

  • test_default_scores_this_year_highest: with the default, a URL dated this year scores 1.0 and above last year's, an older one and an undated one. Fails on develop.
  • test_explicit_current_year_is_still_honoured: FreshnessScorer(current_year=2024) behaves as before.
  • tests/general/test_deep_crawl_scorers.py passes.

Checklist:

  • My code follows the style guidelines of this project (black adds nothing new)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added/updated unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Written with AI assistance; I reviewed the change and ran the tests myself.

current_year defaulted to a hard-coded 2024, and years after current_year are
discarded as invalid, so from 2025 on a URL dated this year scored 0.5, the
same as an undated one, while 2024 content scored highest. Default to
date.today().year; an explicit current_year still works as before.

@SohamKukreti SohamKukreti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Siddharth-DWT, this is a clean, minimal fix.

Review

  • The change is small and does only one thing. If you pass current_year yourself, by name or by position, it works the same as before. If you do not pass it, the scorer uses the current year, which fixes #2426.
  • Saving and loading the config works the same. The default is still not saved, so a loaded scorer uses the current year, not 2024.
  • test_default_scores_this_year_highest catches the bug: it fails on develop and passes here.
  • Nit (does not block the merge): test_explicit_current_year_is_still_honoured mostly repeats tests/general/test_deep_crawl_scorers.py, which already uses current_year=2024. You can keep it or remove it.

Testing

  • I ran the scorer, filter, deep-crawl and security tests on this branch and on develop. The results are the same, and the 2 new tests pass.
  • I ran a live crawl of https://blog.rust-lang.org/ with BestFirstCrawlingStrategy and the default FreshnessScorer(). On develop, it took 13 posts from 2024 and 1 from 2023, and every 2026 post scored 0.5. On this branch, it took 14 posts from 2026, each with a score of 1.0.

LGTM. Thanks for the fix!

@Siddharth-DWT

Copy link
Copy Markdown
Author

Thanks for the review, and for checking it on a live crawl. I'll keep test_explicit_current_year_is_still_honoured as a guard for explicit years, unless you'd rather I drop it.

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.

3 participants