Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ページの別名で検索できるようにした #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
faithandbrave merged 1 commit into master from alias_search
Jan 7, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions js/crsearch/database.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 24 additions & 3 deletions js/crsearch/index.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down

AltStyle によって変換されたページ (->オリジナル) /