Skip to content
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
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
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