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
  • Loading branch information
mykola committed Jan 2, 2025
1 parent 01c6afd commit 3b25bec
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { RelatedKeywordScoreAggregator } from "../../../src/scoring/scoreAggregators";
import AssessmentResult from "../../../src/values/AssessmentResult";

describe( "RelatedKeywordScoreAggregator", () => {
let aggregator;

beforeEach( () => {
aggregator = new RelatedKeywordScoreAggregator();
} );

describe( "aggregate", () => {
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 );
} );
} );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import SEOScoreAggregator from "./SEOScoreAggregator";

/**
* Aggregates SEO assessment results into a single score.
*
* @memberOf module:parsedPaper/assess
*/
class RelatedKeywordScoreAggregator extends SEOScoreAggregator {
/**
* 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.
*
* @param {AssessmentResult[]} results The assessment results.
*
* @returns {number} The aggregated score.
*/
aggregate( results ) {
const validResults = this.getValidResults( results );

return super.aggregate( validResults );
}
}

export default RelatedKeywordScoreAggregator;
1 change: 1 addition & 0 deletions packages/yoastseo/src/scoring/scoreAggregators/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as ReadabilityScoreAggregator } from "./ReadabilityScoreAggregator";
export { default as RelatedKeywordScoreAggregator } from "./RelatedKeywordScoreAggregator";
export { default as ScoreAggregator } from "./ScoreAggregator";
export { default as SEOScoreAggregator } from "./SEOScoreAggregator";
5 changes: 3 additions & 2 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 } from "../scoring/scoreAggregators";
import { ReadabilityScoreAggregator, SEOScoreAggregator, RelatedKeywordScoreAggregator } from "../scoring/scoreAggregators";

const logger = getLogger( "yoast-analysis-worker" );
logger.setDefaultLevel( "error" );
Expand Down Expand Up @@ -313,6 +313,7 @@ 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 @@ -1241,7 +1242,7 @@ export default class AnalysisWebWorker {
const analysisCombination = {
oldAssessor: this._relatedKeywordAssessor,
treeAssessor: this._relatedKeywordTreeAssessor,
scoreAggregator: this._seoScoreAggregator,
scoreAggregator: this._relatedKeywordScoreAggregator,
};

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

0 comments on commit 3b25bec

Please sign in to comment.