Skip to content

Commit

Permalink
Related keyphrase status neutral/orange instead of happy/green when a…
Browse files Browse the repository at this point in the history
…ll the results are good

#4475
Remove related keyword score aggregator and move filter into base SEOScoreAggregator
  • Loading branch information
mykola committed Jan 9, 2025
1 parent 1241e1e commit 3d3449d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 168 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,17 @@ describe( "SEOScoreAggregator", () => {
const score = aggregator.aggregate( results );
expect( score ).toBe( 63 );
} );

it( "exclude assessments without score from aggregator", () => {
const results = [
new AssessmentResult( { score: 5 } ),
new AssessmentResult(),
new AssessmentResult( { score: 4 } ),
new AssessmentResult( { score: 8 } ),
new AssessmentResult(),
];
const score = aggregator.aggregate( results );
expect( score ).toBe( 63 );
} );
} );
} );

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ const ScoreFactor = 9;
* @memberOf module:parsedPaper/assess
*/
class SEOScoreAggregator extends ScoreAggregator {
/**
* Returns the list of valid results.
* Valid results are all results that have a score.
*
* @param {AssessmentResult[]} results The results to filter the valid results from.
*
* @returns {AssessmentResult[]} The list of valid results.
*/
getValidResults( results ) {
return results.filter( result => result.hasScore() );
}

/**
* Aggregates the given assessment results into a single score.
*
Expand All @@ -40,14 +52,16 @@ class SEOScoreAggregator extends ScoreAggregator {
* @returns {number} The aggregated score.
*/
aggregate( results ) {
const score = results.reduce( ( sum, result ) => sum + result.getScore(), 0 );
const validResults = this.getValidResults( results );

const score = validResults.reduce( ( sum, result ) => sum + result.getScore(), 0 );

/*
* Whenever the divide by part is 0 this can result in a `NaN` value. Then 0 should be returned as fallback.
* This seemed better than the if check `results.length === 0`,
* This seemed better than the if check `validResults.length === 0`,
* because it also protects against ScoreFactor being 0.
*/
return Math.round( ( score * ScoreScale ) / ( results.length * ScoreFactor ) ) || 0;
return Math.round( ( score * ScoreScale ) / ( validResults.length * ScoreFactor ) ) || 0;
}
}

Expand Down
5 changes: 2 additions & 3 deletions packages/yoastseo/src/worker/AnalysisWebWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import SEOAssessor from "../scoring/assessors/seoAssessor.js";
import TaxonomyAssessor from "../scoring/assessors/taxonomyAssessor.js";

// Tree assessor functionality.
import { ReadabilityScoreAggregator, SEOScoreAggregator, RelatedKeywordScoreAggregator } from "../scoring/scoreAggregators";
import { ReadabilityScoreAggregator, SEOScoreAggregator } from "../scoring/scoreAggregators";

const logger = getLogger( "yoast-analysis-worker" );
logger.setDefaultLevel( "error" );
Expand Down Expand Up @@ -313,7 +313,6 @@ export default class AnalysisWebWorker {
// Score aggregators
this._seoScoreAggregator = new SEOScoreAggregator();
this._contentScoreAggregator = new ReadabilityScoreAggregator();
this._relatedKeywordScoreAggregator = new RelatedKeywordScoreAggregator();

// Tree representation of text to analyze
this._tree = null;
Expand Down Expand Up @@ -1248,7 +1247,7 @@ export default class AnalysisWebWorker {
const analysisCombination = {
oldAssessor: this._relatedKeywordAssessor,
treeAssessor: this._relatedKeywordTreeAssessor,
scoreAggregator: this._relatedKeywordScoreAggregator,
scoreAggregator: this._seoScoreAggregator,
};

// We need to remember the key, since the SEO results are stored in an object, not an array.
Expand Down

0 comments on commit 3d3449d

Please sign in to comment.