Skip to content

Commit

Permalink
fix(scrape parser): Cannot read properties of 'undefined' during page…
Browse files Browse the repository at this point in the history
… parsing (#1274)

fix(scrape parser): Cannot read properties of undefined (reading percentageTextShare) during page parsing

Co-authored-by: Nathan Sarrazin <sarrazin.nathan@gmail.com>
  • Loading branch information
neven4 and nsarrazin authored Jun 14, 2024
1 parent 7db9de5 commit 654df51
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/server/websearch/scrape/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ export function spatialParser() {
});

// if there is a dominant cluster with more than 60% text share, return that
const dominantCluster = clusterWithMetrics[0].percentageTextShare > 60;
const dominantCluster = clusterWithMetrics[0]?.percentageTextShare > 60;
if (dominantCluster) return [clusterWithMetrics[0].cluster];

// clusters are sorted by text share after applying a penalty for centrality
Expand All @@ -448,7 +448,7 @@ export function spatialParser() {
// find all clusters that are similar to the largest cluster in terms of text share
// and see if they are enough to cover at least 60% of the text share
const largeTextShareClusters = sortedClusters.filter((c) =>
approximatelyEqual(c.percentageTextShare, sortedClusters[0].percentageTextShare, 10)
approximatelyEqual(c.percentageTextShare, sortedClusters[0]?.percentageTextShare, 10)
);

const totalTextShareOfLargeClusters = largeTextShareClusters.reduce(
Expand Down

0 comments on commit 654df51

Please sign in to comment.