Skip to content

Commit 70730e3

Browse files
committed
ページの別名で検索できるようにした
1 parent ecbdea6 commit 70730e3

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

js/crsearch/index.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,24 @@ export default class Index {
2121
this._related_to = json.related_to
2222
this._nojump = !!json.nojump
2323
this._attributes = json.attributes
24+
this._aliases = json.aliases || []
2425
} else {
2526
// this._log.debug('fake Index created')
2627
this._page_id = id.keys.slice(-1)
28+
this._aliases = []
29+
}
30+
31+
// 名前空間付きエイリアスを事前計算(例:['string'] -> ['std::string'])
32+
if (IType.isClassy(this._id.type)) {
33+
const nsKeys = this._id.keys.slice(0, -1)
34+
if (nsKeys.length > 0) {
35+
const nsPrefix = nsKeys.join('::') + '::'
36+
this._namespacedAliases = this._aliases.map(alias => nsPrefix + alias)
37+
} else {
38+
this._namespacedAliases = this._aliases
39+
}
40+
} else {
41+
this._namespacedAliases = this._aliases
2742
}
2843

2944
Object.seal(this)
@@ -71,18 +86,24 @@ export default class Index {
7186

7287
ambgMatch(q) {
7388
if (IType.isArticles(this._id.type)) {
74-
return this._name.toLowerCase().includes(q.toLowerCase())
89+
const lowerQ = q.toLowerCase()
90+
return this._name.toLowerCase().includes(lowerQ) ||
91+
this._aliases.some(alias => alias.toLowerCase().includes(lowerQ))
7592
}
7693

77-
return this._name.includes(q)
94+
return this._name.includes(q) ||
95+
this._namespacedAliases.some(alias => alias.includes(q))
7896
}
7997

8098
ambgMatchMulti(q) {
8199
if (IType.isArticles(this._id.type)) {
82-
return this._name.toLowerCase().includes(q.toLowerCase())
100+
const lowerQ = q.toLowerCase()
101+
return this._name.toLowerCase().includes(lowerQ) ||
102+
this._aliases.some(alias => alias.toLowerCase().includes(lowerQ))
83103
}
84104

85105
return this._name.includes(q) ||
106+
this._namespacedAliases.some(alias => alias.includes(q)) ||
86107
this._in_header && this._in_header._name.includes(q) ||
87108
this._parent && this._parent._name.includes(q)
88109
}

0 commit comments

Comments
 (0)