From cce4f38cf8e8e6710ab8d3a6e8cb308cd6e6ac13 Mon Sep 17 00:00:00 2001 From: Akira Takahashi Date: Wed, 7 Jan 2026 22:16:26 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=9A=E3=83=BC=E3=82=B8=E3=81=AE=E5=88=A5?= =?UTF-8?q?=E5=90=8D=E3=81=A7=E6=A4=9C=E7=B4=A2=E3=81=A7=E3=81=8D=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/crsearch/database.js | 16 ++++++++++++++++ js/crsearch/index.js | 27 ++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/js/crsearch/database.js b/js/crsearch/database.js index 995f94f..5956f03 100644 --- a/js/crsearch/database.js +++ b/js/crsearch/database.js @@ -86,6 +86,22 @@ export default class Database { if (aExactFull && !bExactFull) return -1 if (!aExactFull && bExactFull) return 1 + // エイリアス(名前空間付き)での完全一致を判定 + const aExactAlias = q._and.some(s => aidx._namespacedAliases && aidx._namespacedAliases.includes(s)) + const bExactAlias = q._and.some(s => bidx._namespacedAliases && bidx._namespacedAliases.includes(s)) + + // エイリアス(名前空間付き)での完全一致を優先 + if (aExactAlias && !bExactAlias) return -1 + if (!aExactAlias && bExactAlias) return 1 + + // エイリアス(名前空間なし)での完全一致を判定 + const aExactAliasShort = q._and.some(s => aidx._aliases && aidx._aliases.includes(s)) + const bExactAliasShort = q._and.some(s => bidx._aliases && bidx._aliases.includes(s)) + + // エイリアス(名前空間なし)での完全一致を優先 + if (aExactAliasShort && !bExactAliasShort) return -1 + if (!aExactAliasShort && bExactAliasShort) return 1 + // 名前空間を除いた部分での完全一致を判定 const aExactPart = q._and.some(s => getLastPart(aidx._name) === s) const bExactPart = q._and.some(s => getLastPart(bidx._name) === s) diff --git a/js/crsearch/index.js b/js/crsearch/index.js index 5380e1c..1eb90a9 100644 --- a/js/crsearch/index.js +++ b/js/crsearch/index.js @@ -21,9 +21,24 @@ export default class Index { this._related_to = json.related_to this._nojump = !!json.nojump this._attributes = json.attributes + this._aliases = json.aliases || [] } else { // this._log.debug('fake Index created') this._page_id = id.keys.slice(-1) + this._aliases = [] + } + + // 名前空間付きエイリアスを事前計算(例:['string'] -> ['std::string']) + if (IType.isClassy(this._id.type)) { + const nsKeys = this._id.keys.slice(0, -1) + if (nsKeys.length > 0) { + const nsPrefix = nsKeys.join('::') + '::' + this._namespacedAliases = this._aliases.map(alias => nsPrefix + alias) + } else { + this._namespacedAliases = this._aliases + } + } else { + this._namespacedAliases = this._aliases } Object.seal(this) @@ -71,18 +86,24 @@ export default class Index { ambgMatch(q) { if (IType.isArticles(this._id.type)) { - return this._name.toLowerCase().includes(q.toLowerCase()) + const lowerQ = q.toLowerCase() + return this._name.toLowerCase().includes(lowerQ) || + this._aliases.some(alias => alias.toLowerCase().includes(lowerQ)) } - return this._name.includes(q) + return this._name.includes(q) || + this._namespacedAliases.some(alias => alias.includes(q)) } ambgMatchMulti(q) { if (IType.isArticles(this._id.type)) { - return this._name.toLowerCase().includes(q.toLowerCase()) + const lowerQ = q.toLowerCase() + return this._name.toLowerCase().includes(lowerQ) || + this._aliases.some(alias => alias.toLowerCase().includes(lowerQ)) } return this._name.includes(q) || + this._namespacedAliases.some(alias => alias.includes(q)) || this._in_header && this._in_header._name.includes(q) || this._parent && this._parent._name.includes(q) }