Skip to content

Adjust scoring criteria for the keyphrase density assessment for short texts#22715

Merged
marinakoleva merged 10 commits intofeature/off-the-bat-analysisfrom
adjust-keyphrase-density-scoring-criteria-for-short-texts
Nov 17, 2025
Merged

Adjust scoring criteria for the keyphrase density assessment for short texts#22715
marinakoleva merged 10 commits intofeature/off-the-bat-analysisfrom
adjust-keyphrase-density-scoring-criteria-for-short-texts

Conversation

@agnieszkaszuba
Copy link
Copy Markdown
Contributor

@agnieszkaszuba agnieszkaszuba commented Nov 12, 2025

Context

  • After making the keyphrase density assessment available off the bat, we want to adjust the scoring criteria for short texts (< 100 words), which the assessment was previously not available for. The keyphrase density formula does not work well with shorter texts, so instead we want to give a score based on the number of keyphrase occurrences found for short texts.

Summary

This PR can be summarized in the following changelog entry:

  • Adjusts the scoring criteria for the keyphrase density assessment for texts shorter than 100 words.
  • [shopify-seo] Adjusts the scoring criteria for the keyphrase density assessment for texts shorter than 100 words.
  • [yoast-doc-extension] Adjusts the scoring criteria for the keyphrase density assessment for texts shorter than 100 words.
  • [yoastseo enhancement] Adjusts the scoring criteria in keyphrase density assessment for texts shorter than 100 words.

Relevant technical choices:

  • I have refactored the code in getResult a bit so that if the paper has no keyphrase or text, we don't run unnecessary code.
  • I have adjusted the feedback strings for when there are too few/too many instances of the keyphrase so that both the first and second sentence can have different translations depending on the number. This is especially important for the short texts where the minimum/maximum recommended number of keyphrases can be 1. But also for long texts, even though the minimum/maximum recommended number of keyphrases will always be higher than 1, in some languages different translations may be needed for different numbers.
  • Following the PR to Adjust keyphrase distribution scoring for short texts, keyphraseDistractionPercentage was refactored to use camelCase in order to follow JS conventions.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

Note

  • The testing steps are the same for WordPress, Shopify, and Google Docs extension)
  • However, AI Optimize is not yet integrated into Shopify and Google Docs extension. Hence you can skip the testing steps related to AI Optimize in Shopify and Goggle Docs extension app.
  • Additionally, the highlighting button testing steps are also not relevant for Google docs extension app since it's not supported there yet

Text with 50 words or less

  • Activate Yoast SEO and Yoast SEO Premium
  • Create a post / product / Google doc
  • Don't add any text or keyphrase
  • Confirm that the keyphrase density assessment feedback shows a red traffic light and the following feedback:
    • Keyphrase density: Please add both a keyphrase and some text containing the keyphrase.
  • Confirm that the highlighting button is not present, and that the AI Optimize button is present but disabled
  • Add a block that's excluded from the analysis, e.g. a Yoast Breadcrumbs block or a Blockquote in Classic/ Woo.
  • Confirm that the keyphrase density assessment feedback stays the same
  • Add the following keyphrase: red panda
  • ⚠️ Note that the behaviour here is a known limitation. Keyphrase density returns "The keyphrase was found 0 times. That's less than the recommended minimum of 1 time for a text of this length. Focus on your keyphrase!" instead of the correct feedback, "Please add both a keyphrase and some text containing the keyphrase or its synonyms." Here is the issue to fix it: Off the bat: Keyphrase density & introduction consider text with excluded blocks/ spaces as valid
  • Add the following text (38 words):
    • Giant pandas conservation efforts have significantly improved their survival prospects over the past few decades. These giant pandas conservation efforts include the creation of more than 60 protected reserves in China. The reserves safeguard essential bamboo forest habitats.
  • Confirm that the keyphrase density assessment feedback shows a red traffic light and the following feedback:
    • Keyphrase density: The keyphrase was found 0 times. That's less than the recommended minimum of 1 time for a text of this length. Focus on your keyphrase!
  • Confirm that the highlighting button is not present and that the AI Optimize button is present and enabled
  • Change the keyphrase to: panda protected reserves
  • Confirm that the keyphrase density assessment feedback shows a green traffic light and the following feedback:
    • Keyphrase density: The keyphrase was found 1 time. This is great!
  • Confirm that the highlighting button is present, and the AI Optimize button is not present
  • Change the keyphrase to: giant panda
  • Confirm that the keyphrase density assessment feedback shows a red traffic light and the following feedback:
    • Keyphrase density: The keyphrase was found 2 times. That's more than the recommended maximum of 1 time for a text of this length. Don't overoptimize!
  • Confirm that the highlighting button is present, and the AI Optimize button is not present
  • Add the keyphrase 'giant panda' somewhere else in the text
  • Confirm that the keyphrase density assessment feedback shows a red traffic light and the following feedback:
    • Keyphrase density: The keyphrase was found 3 times. That's way more than the recommended maximum of 1 time for a text of this length. Don't overoptimize!
  • Confirm that the highlighting button is present, and the AI Optimize button is not present

Text with 51-99 words

  • Activate Yoast SEO and Yoast SEO Premium
  • Create a post / product / Google doc
  • Add the following keyphrase: red panda
  • Add the following text (78 words):
    • Giant pandas conservation efforts have significantly improved their survival prospects over the past few decades. These giant pandas conservation efforts include the creation of more than 60 protected reserves in China. The reserves safeguard essential bamboo forest habitats. Breeding programs, habitat restoration, and international partnerships are all key components of the conservation efforts of giant pandas. They help to boost both wild and captive populations. The Chinese government, along with global wildlife organizations, continues to prioritize these initiatives.
  • Confirm that the keyphrase density assessment feedback shows a red traffic light and the following feedback:
    • Keyphrase density: The keyphrase was found 0 times. That's less than the recommended minimum of 1 time for a text of this length. Focus on your keyphrase!
  • Confirm that the highlighting button is not present and that the AI Optimize button is present and enabled
  • Change the keyphrase to: panda protected reserves
  • Confirm that the keyphrase density assessment feedback shows a green traffic light and the following feedback:
    • Keyphrase density: The keyphrase was found 1 time. This is great!
  • Confirm that the highlighting button is present, and the AI Optimize button is not present
  • Change the keyphrase to: reserves
  • Confirm that the keyphrase density assessment feedback shows a green traffic light and the following feedback:
    • Keyphrase density: The keyphrase was found 2 times. This is great!
  • Confirm that the highlighting button is present, and the AI Optimize button is not present
  • Change the keyphrase to: giant panda
  • Confirm that the keyphrase density assessment feedback shows a red traffic light and the following feedback:
    • Keyphrase density: The keyphrase was found 3 times. That's more than the recommended maximum of 2 times for a text of this length. Don't overoptimize!
  • Confirm that the highlighting button is present, and the AI Optimize button is not present
  • Add the keyphrase 'giant panda' somewhere else in the text
  • Confirm that the keyphrase density assessment feedback shows a red traffic light and the following feedback:
    • Keyphrase density: The keyphrase was found 4 times. That's way more than the recommended maximum of 2 times for a text of this length. Don't overoptimize!
  • Confirm that the highlighting button is present, and the AI Optimize button is not present

Test with 100 or more words

  • Activate Yoast SEO and Yoast SEO Premium
  • Create a post / product / Google doc
  • Add the following keyphrase: red panda
  • Add the following text (135 words):
    • Giant pandas conservation efforts have significantly improved their survival prospects over the past few decades. These giant pandas conservation efforts include the creation of more than 60 protected reserves in China. The reserves safeguard essential bamboo forest habitats. Breeding programs, habitat restoration, and international partnerships are all key components of the conservation efforts of giant pandas. They help to boost both wild and captive populations. The Chinese government, along with global wildlife organizations, continues to prioritize these initiatives. This will help to ensure long-term species stability. As a result of sustained conservation efforts of giant pandas, the IUCN reclassified the species from “Endangered” to “Vulnerable” in 2016. Ongoing monitoring and community engagement remain crucial to maintaining this conservation success. In 2020, the giant panda population of the new national park was already above 1,800 individuals.
  • Confirm that the keyphrase density assessment feedback shows a red traffic light and the following feedback:
    • Keyphrase density: The keyphrase was found 0 times. That's less than the recommended minimum of 2 times for a text of this length. Focus on your keyphrase!
  • Confirm that the highlighting button is not present and that the AI Optimize button is present and enabled
  • Change the keyphrase to: panda protected reserves
  • Confirm that the keyphrase density assessment feedback shows a red traffic light and the following feedback:
    • Keyphrase density: The keyphrase was found 1 time. That's less than the recommended minimum of 2 times for a text of this length. Focus on your keyphrase!
  • Confirm that the highlighting button and the AI Optimize button are both present
  • Add the keyphrase 'panda protected reserves' somewhere else in the text
  • Confirm that the keyphrase density assessment feedback shows a green traffic light and the following feedback:
    • Keyphrase density: The keyphrase was found 2 times. This is great!
  • Confirm that the highlighting button is present, and the AI Optimize button is not present
  • Add the keyphrase 'panda protected reserves' one more time to the text
  • Confirm that the keyphrase density assessment feedback shows a red traffic light and the following feedback:
    • Keyphrase density: The keyphrase was found 3 times. That's more than the recommended maximum of 2 times for a text of this length. Don't overoptimize!
  • Confirm that the highlighting button is present, and the AI Optimize button is not present
  • Change the keyphrase to: giant panda
  • Confirm that the keyphrase density assessment feedback shows a red traffic light and the following feedback:
    • Keyphrase density: The keyphrase was found 5 times. That's way more than the recommended maximum of 3 times for a text of this length. Don't overoptimize!
  • Confirm that the highlighting button is present, and the AI Optimize button is not present

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

QA can test this PR by following these steps:

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.

Documentation

  • I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes Off the bat: Adjust scoring criteria of Keyphrase density assessment for short texts

@agnieszkaszuba agnieszkaszuba added the changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog label Nov 12, 2025
@coveralls
Copy link
Copy Markdown

coveralls commented Nov 12, 2025

Pull Request Test Coverage Report for Build a4f43578060a2303b0856de8504b2cd0a4856caf

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 28 of 28 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 53.458%

Totals Coverage Status
Change from base Build b24f8312b57d41c034c39cbb1f2f5b586dc32023: 0.02%
Covered Lines: 32310
Relevant Lines: 60684

💛 - Coveralls

@agnieszkaszuba agnieszkaszuba added the Shopify This PR impacts Shopify. label Nov 12, 2025
@agnieszkaszuba agnieszkaszuba marked this pull request as ready for review November 12, 2025 15:53
@github-actions
Copy link
Copy Markdown

A merge conflict has been detected for the proposed code changes in this PR. Please resolve the conflict by either rebasing the PR or merging in changes from the base branch.

@marinakoleva
Copy link
Copy Markdown
Contributor

CR & AT done ✔️

  • Updated the structure of the Keyphrase density table in the Github documentation page on SEO assessments.
  • Created a separate issue Off the bat: Keyphrase density & introduction consider text with excluded blocks/ spaces as valid but it doesn't have big priority, in fact it could be accepted as a limitation of the assessment's behaviour.
  • Haven't tested the changes in Shopify, but have tested them on a product page in Woo.
  • Made a small unrelated change explained in the technical choices:

Following the PR to #22694, keyphraseDistractionPercentage was refactored to use camelCase in order to follow JS conventions.

@marinakoleva marinakoleva merged commit cd8b8c4 into feature/off-the-bat-analysis Nov 17, 2025
22 checks passed
@marinakoleva marinakoleva deleted the adjust-keyphrase-density-scoring-criteria-for-short-texts branch November 17, 2025 14:40
@marinakoleva
Copy link
Copy Markdown
Contributor

These changes were not applied to Japanese. Here's the issue to fix that: Off the bat: Fix Keyphrase density for short texts in Japanese

@FAMarfuaty FAMarfuaty added the Google Docs Add-on If this PR is also relevant or has an impact on the Google Docs Add-on label Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog Google Docs Add-on If this PR is also relevant or has an impact on the Google Docs Add-on Shopify This PR impacts Shopify.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants