error checking in looking up latest version

Chris Pollett [2023-12-12 22:Dec:th]
error checking in looking up latest version
Filename
src/library/IndexManager.php
src/library/index_bundle_iterators/IndexBundleIterator.php
src/library/index_bundle_iterators/WordIterator.php
src/models/PhraseModel.php
diff --git a/src/library/IndexManager.php b/src/library/IndexManager.php
index da7cd7f41..6cb400945 100644
--- a/src/library/IndexManager.php
+++ b/src/library/IndexManager.php
@@ -397,12 +397,12 @@ class IndexManager implements CrawlConstants
         $page_versions = $model_for_url_hash_lookup->
             lookupSummaryOffsetGeneration(L\base64Hash($url_hash),
             $index_name, false, true);
-        if (key_exists('ROWS', $page_versions) &&
+        if (!empty($page_versions['ROWS']) && ) &&
             count($page_versions['ROWS']) > 0) {
             $latest_postings_info =
-                end($page_versions['ROWS'])['POSTINGS'];
+                end($page_versions['ROWS'])['POSTINGS'] ?? null;
             $latest_partition =
-                end($page_versions['ROWS'])['PARTITION'];
+                end($page_versions['ROWS'])['PARTITION'] ?? null;
             if (is_array($latest_postings_info) &&
                 count($latest_postings_info) > 0) {
                 $latest_posting = end($latest_postings_info);
diff --git a/src/library/index_bundle_iterators/IndexBundleIterator.php b/src/library/index_bundle_iterators/IndexBundleIterator.php
index e1554322d..4042566e0 100644
--- a/src/library/index_bundle_iterators/IndexBundleIterator.php
+++ b/src/library/index_bundle_iterators/IndexBundleIterator.php
@@ -299,7 +299,15 @@ abstract class IndexBundleIterator implements CrawlConstants
         $this->results_per_block = $num;
      }
      /**
-      *
+      * @param string $doc_key
+      * @param int $doc_map_index
+      * @param int $num_seen_partitions
+      * @param int $number_of_partitions
+      * @param int $num_doc_keys
+      * @param float $avg_items_per_partition
+      * @param int $max_items_per_partition
+      * @param array $ranking_factors
+      * @param bool $is_ascending
       */
     public function computeDocRank($doc_key, $doc_map_index = 1,
         $num_seen_partitions = 0, $number_of_partitions = 1,
diff --git a/src/library/index_bundle_iterators/WordIterator.php b/src/library/index_bundle_iterators/WordIterator.php
index 0477d85d1..5008a2bcd 100644
--- a/src/library/index_bundle_iterators/WordIterator.php
+++ b/src/library/index_bundle_iterators/WordIterator.php
@@ -696,8 +696,9 @@ class WordIterator extends IndexBundleIterator
                     $posting["TITLE_END_POS"],
                     $posting["PATH_KEYWORDS_END_POS"],
                     $posting[self::DESCRIPTION_SCORES]);
+                $count_bonus = ($bonuses > 0) ?  : 0;
                 // Divergence-from-randomness + preface score
-                $posting[self::RELEVANCE] = 2.5 * $bonuses *
+                $posting[self::RELEVANCE] = $count_bonus + 2.5 * $bonuses *
                     log(1 + 1/max(1, $occurrences_per_doc), 2) /
                     ($bonuses + 1) +
                     ((log(1 + $occurrences_per_doc, 2) + $frequency *
@@ -812,7 +813,7 @@ class WordIterator extends IndexBundleIterator
                 $start_description_pos;
             $frequency_term = $weight * $len_term / $len_description;
             if ($position <= 0) {
-                $bonuses += $frequency_term;
+                $bonuses += $weight; //$frequency_term;
             } else {
                 $weighted_frequency += $frequency_term;
             }
diff --git a/src/models/PhraseModel.php b/src/models/PhraseModel.php
index e545c9ebf..349ed503a 100755
--- a/src/models/PhraseModel.php
+++ b/src/models/PhraseModel.php
@@ -579,6 +579,10 @@ class PhraseModel extends ParallelModel
      */
     public function rewriteAsDisjunctiveQuery($phrase)
     {
+        if (($new_phrase =
+            preg_replace('/no\:rewrite/', ' ', $phrase)) != $phrase) {
+            return $new_phrase;
+        }
         $phrase = preg_replace('/\s+/', ' ', $phrase);
         $locale_tag = L\guessLocaleFromString($phrase);
         $search_terms = [];
@@ -601,7 +605,7 @@ class PhraseModel extends ParallelModel
          */
         for ($i = 0; $i < $num_phrase_parts; $i++) {
             while ($i < $num_phrase_parts - 1 &&
-                $split_phrase[$i + 1] == '_and') {
+                in_array($split_phrase[$i + 1], ['_', '_a', '_and'])) {
                 $s .= $split_phrase[$i] . " ";
                 $i += 2;
             }
ViewGit