protected static function matchWords()

in src/search/SearchTermMatcher.php [158:193]


  protected static function matchWords(
    string $content,
    string $term,
    keyset<string> $terms,
  ): ?float {
    $parts = Str\split($term, ' ');
    if (C\count($parts) === 1) {
      return null;
    }

    $terms = Keyset\union($terms, $parts);

    $total = 0.0;
    foreach ($parts as $idx => $part) {
      $score = self::matchTermInner($content, $part, $terms);
      if ($score === null) {
        return null;
      }
      $total += $score;
    }
    $score = $total / C\count($parts);

    $idx = 0;
    foreach ($parts as $part) {
      $new_idx = $part
        |> Keyset\union(vec[$$], self::SYNONYMS[Str\lowercase($$)] ?? vec[])
        |> Vec\map($$, $part ==> Str\search($content, $part, $idx + 1))
        |> Vec\filter_nulls($$)
        |> Math\min($$);
      if ($new_idx === null) {
        return $score * SearchScores::OUT_OF_ORDER_WORD_SPLIT_MULTIPLIER;
      }
      $idx = $new_idx;
    }
    return $score * SearchScores::IN_ORDER_WORD_SPLIT_MULTIPLIER;
  }