Fix for backward compatibility of IndexDocumentBundle::isType() with old letter code format

Gargi Sheguri [2023-09-22 02:Sep:nd]
Fix for backward compatibility of IndexDocumentBundle::isType() with old letter code format

Signed-off-by: Chris Pollett <chris@pollett.org>
Filename
src/library/IndexDocumentBundle.php
diff --git a/src/library/IndexDocumentBundle.php b/src/library/IndexDocumentBundle.php
index 21668fa12..42661a6b6 100644
--- a/src/library/IndexDocumentBundle.php
+++ b/src/library/IndexDocumentBundle.php
@@ -1214,6 +1214,21 @@ class IndexDocumentBundle implements CrawlConstants
             56 => "text",
             64 => "video",
         ];
+        /**
+         * This map is maintained for backward compatibility, i.e., for the $key values
+         * using the previous letter code format.
+         */
+        $old_type_map = [
+            "b" => "binary",
+            "d" => "old_doc",
+            "e" => "external_link",
+            "f" => "feed",
+            "i" => "internal_link",
+            "l" => "old_link",
+            "p" => "image",
+            "t" => "text",
+            "v" => "video",
+        ];
         if (is_string($types)) {
             $types = [$types];
         }
@@ -1224,8 +1239,14 @@ class IndexDocumentBundle implements CrawlConstants
             $types = array_merge($types, ["binary", "feed", "image",
                 "old_doc", "text", "video"]);
         }
-        $key_type = ord($key[self::DOCID_PART_LEN << 1] ?? 0) & 120;
-        return in_array($type_map[$key_type] ?? "old_link", $types);
+        $doc_id_format = ord($key[self::DOCID_PART_LEN << 1] ?? 0) & 96;
+        if ($doc_id_format != 96) {
+            $key_type = ord($key[self::DOCID_PART_LEN << 1] ?? 0) & 120;
+            return in_array($type_map[$key_type] ?? "old_link", $types);
+        }
+        // $key uses the old letter code format
+        $key_type = chr(ord($key[self::DOCID_PART_LEN << 1] ?? 0) & 127);
+        return in_array($old_type_map[$key_type] ?? "old_link", $types);
     }
     /**
      * As pre-step to calculating the inverted index information for a partition
ViewGit