Repository: huhu/rust-search-extension (language: rust)

Issue:
search doesn't work sometimes
search doesn't work sometimes

## Information
- Chromium Version 111.0.5563.146 (Official Build) Arch Linux (64-bit)
- Rust Search Extension 1.10.0

## logs
```log
base.js:505 Uncaught (in promise) TypeError: result.item.path.toLowerCase is not a function
    at SingleCrateDocSearch.sortResults (base.js:505:41)
    at SingleCrateDocSearch.execQuery (base.js:397:21)
    at SingleCrateDocSearch.search (base.js:71:21)
    at CrateDocSearch.searchAll (crate-doc.js:80:38)
    at async QueryEvent.onSearch (main.js:204:20)
    at async QueryEvent.performSearch (query-event.js:34:22)
    at async Omnibox.performSearch (omnibox.js:200:32)
    at async omnibox.js:81:27
sortResults @ base.js:505
execQuery @ base.js:397
search @ base.js:71
searchAll @ crate-doc.js:80
await in searchAll (async)
(anonymous) @ extensions::omnibox:121
```



Discussion / hints:
Hi, @notriddle. My extension is broken again due to the changes in the search index. It seems like the `item.path` has been changed from string to array. Do you know which PR brought such a change? I hope I can figure out how to fix it based on that PR. Thanks. ❤️ 

<img width="708" alt="image" src="https://user-images.githubusercontent.com/3369694/229296498-d0f684a1-db07-493a-beb1-a10ccc7c1519.png">


I found the PR with the breaking change:  https://github.com/rust-lang/rust/pull/107629

Fix patch:
diff --git a/extension/search/docs/base.js b/extension/search/docs/base.js
index f82f3753..276e80c2 100644
--- a/extension/search/docs/base.js
+++ b/extension/search/docs/base.js
@@ -99,7 +99,18 @@ class DocSearch {
                 // an array of (String) item names
                 const itemNames = indexItem.n;
                 // an array of (String) full paths (or empty string for previous path)
-                const itemPaths = indexItem.q;
+                let itemPaths = indexItem.q;
+                if (itemPaths.length > 0 && Array.isArray(itemPaths[0])) {
+                    // an array of [(Number) item index,
+                    //              (String) full path]
+                    // an item whose index is not present will fall back to the previous present path
+                    // i.e. if indices 4 and 11 are present, but 5-10 and 12-13 are not present,
+                    // 5-10 will fall back to the path for 4 and 12-13 will fall back to the path for 11
+                    // 
+                    // Since Rust 1.70 this is a Map instead of an array.
+                    // See https://github.com/rust-lang/rust/pull/107629
+                    itemPaths = new Map(indexItem.q);
+                }
                 // an array of (String) descriptions
                 const itemDescs = indexItem.d;
                 // an array of (Number) the parent path index + 1 to `paths`, or 0 if none
@@ -128,6 +139,15 @@ class DocSearch {
                 let lastPath = "";
                 for (let i = 0; i < len; ++i) {
                     let ty = itemTypes[i];
+                    let path = lastPath;
+                    // check if itemPaths is map
+                    // Since Rust 1.70, the itemPaths has changed from array to map.
+                    // See https://github.com/rust-lang/rust/pull/107629
+                    if (itemPaths instanceof Map) {
+                        path = itemPaths.get(i) || lastPath;
+                    } else {
+                        path = itemPaths[i] || lastPath;
+                    }
                     let row = {
                         crate: crateName,
                         // itemTypes changed from number array to string since Rust 1.69,
@@ -135,7 +155,7 @@ class DocSearch {
                         // see this PR: https://github.com/rust-lang/rust/pull/108013 
                         ty: typeof ty === 'string' ? itemTypes.charCodeAt(i) - charA : ty,
                         name: itemNames[i],
-                        path: itemPaths[i] ? itemPaths[i] : lastPath,
+                        path,
                         desc: itemDescs[i],
                         parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined,
                         type: itemFunctionSearchTypes[i],


Test patch: