mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-14 15:47:12 +00:00
Dependency injection DocSearch's searchState
This commit is contained in:
parent
fd6140ac38
commit
bda7ca3e82
2 changed files with 7 additions and 8 deletions
|
@ -1,5 +1,3 @@
|
||||||
import searchState from "./desc-shard.js";
|
|
||||||
|
|
||||||
// polyfill
|
// polyfill
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced
|
||||||
if (!Array.prototype.toSpliced) {
|
if (!Array.prototype.toSpliced) {
|
||||||
|
@ -1090,7 +1088,7 @@ class RoaringBitmapBits {
|
||||||
|
|
||||||
|
|
||||||
export default class DocSearchV2 {
|
export default class DocSearchV2 {
|
||||||
constructor(rawSearchIndex, rootPath) {
|
constructor(rawSearchIndex, rootPath, searchState) {
|
||||||
/**
|
/**
|
||||||
* @type {Map<String, RoaringBitmap>}
|
* @type {Map<String, RoaringBitmap>}
|
||||||
*/
|
*/
|
||||||
|
@ -1112,6 +1110,7 @@ export default class DocSearchV2 {
|
||||||
this.typeNameIdMap = new Map();
|
this.typeNameIdMap = new Map();
|
||||||
this.ALIASES = new Map();
|
this.ALIASES = new Map();
|
||||||
this.rootPath = rootPath;
|
this.rootPath = rootPath;
|
||||||
|
this.searchState = searchState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special type name IDs for searching by array.
|
* Special type name IDs for searching by array.
|
||||||
|
@ -1722,7 +1721,7 @@ export default class DocSearchV2 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentIndex += itemTypes.length;
|
currentIndex += itemTypes.length;
|
||||||
searchState.descShards.set(crate, descShardList);
|
this.searchState.descShards.set(crate, descShardList);
|
||||||
}
|
}
|
||||||
// Drop the (rather large) hash table used for reusing function items
|
// Drop the (rather large) hash table used for reusing function items
|
||||||
this.TYPES_POOL = new Map();
|
this.TYPES_POOL = new Map();
|
||||||
|
@ -2862,7 +2861,7 @@ export default class DocSearchV2 {
|
||||||
|
|
||||||
const fetchDesc = alias => {
|
const fetchDesc = alias => {
|
||||||
return this.searchIndexEmptyDesc.get(alias.crate).contains(alias.bitIndex) ?
|
return this.searchIndexEmptyDesc.get(alias.crate).contains(alias.bitIndex) ?
|
||||||
"" : searchState.loadDesc(alias);
|
"" : this.searchState.loadDesc(alias);
|
||||||
};
|
};
|
||||||
const [crateDescs, descs] = await Promise.all([
|
const [crateDescs, descs] = await Promise.all([
|
||||||
Promise.all(crateAliases.map(fetchDesc)),
|
Promise.all(crateAliases.map(fetchDesc)),
|
||||||
|
@ -3295,7 +3294,7 @@ export default class DocSearchV2 {
|
||||||
const descs = await Promise.all(list.map(result => {
|
const descs = await Promise.all(list.map(result => {
|
||||||
return this.searchIndexEmptyDesc.get(result.crate).contains(result.bitIndex) ?
|
return this.searchIndexEmptyDesc.get(result.crate).contains(result.bitIndex) ?
|
||||||
"" :
|
"" :
|
||||||
searchState.loadDesc(result);
|
this.searchState.loadDesc(result);
|
||||||
}));
|
}));
|
||||||
for (const [i, result] of list.entries()) {
|
for (const [i, result] of list.entries()) {
|
||||||
result.desc = descs[i];
|
result.desc = descs[i];
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import DocSearchV2 from "./base-v2.js";
|
import DocSearchV2 from "./base-v2.js";
|
||||||
|
|
||||||
export default class DocSearch extends DocSearchV2 {
|
export default class DocSearch extends DocSearchV2 {
|
||||||
constructor(name, searchIndex, rootPath) {
|
constructor(name, searchIndex, rootPath, descShards) {
|
||||||
if (!(searchIndex instanceof Map)) {
|
if (!(searchIndex instanceof Map)) {
|
||||||
searchIndex = new Map(Object.entries(searchIndex));
|
searchIndex = new Map(Object.entries(searchIndex));
|
||||||
}
|
}
|
||||||
super(searchIndex, rootPath);
|
super(searchIndex, rootPath, descShards);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue