koishi-plugin-oni-sync-bot 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -2022,6 +2022,12 @@ bwiki: https://${this.config.domain}/bw/88888888`;
2022
2022
  }
2023
2023
  return null;
2024
2024
  }
2025
+ getCommonPrefixLength(a, b) {
2026
+ const minLen = Math.min(a.length, b.length);
2027
+ let i = 0;
2028
+ while (i < minLen && a[i] === b[i]) i++;
2029
+ return i;
2030
+ }
2025
2031
  calculateScore(page, queryKey, queryPinyinFull, queryPinyinFirst) {
2026
2032
  let score = 0;
2027
2033
  const { title, pinyin_full, pinyin_first } = page;
@@ -2029,13 +2035,16 @@ bwiki: https://${this.config.domain}/bw/88888888`;
2029
2035
  if (pinyin_full.startsWith(queryPinyinFull)) score += 9;
2030
2036
  if (pinyin_full.includes(queryPinyinFull)) score += 8;
2031
2037
  if (pinyin_first.includes(queryPinyinFirst)) score += 6;
2032
- if (queryPinyinFull.includes(
2033
- pinyin_full.substring(
2034
- 0,
2035
- Math.min(pinyin_full.length, queryPinyinFull.length)
2036
- )
2037
- )) {
2038
- score += 5;
2038
+ const titlePrefixLen = this.getCommonPrefixLength(title, queryKey);
2039
+ if (titlePrefixLen >= 2) {
2040
+ score += titlePrefixLen;
2041
+ }
2042
+ const pinyinPrefixLen = this.getCommonPrefixLength(
2043
+ pinyin_full,
2044
+ queryPinyinFull
2045
+ );
2046
+ if (pinyinPrefixLen >= 3) {
2047
+ score += Math.floor(pinyinPrefixLen / 2);
2039
2048
  }
2040
2049
  return score;
2041
2050
  }
@@ -16,6 +16,7 @@ export declare class QueryCommands {
16
16
  private buildResultKeyboard;
17
17
  private renderResultMessage;
18
18
  private findPreciseMatch;
19
+ private getCommonPrefixLength;
19
20
  private calculateScore;
20
21
  private findFuzzyMatches;
21
22
  private handleSelection;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-oni-sync-bot",
3
3
  "description": "缺氧Wiki站镜像点同步-测试",
4
- "version": "0.9.2",
4
+ "version": "0.9.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -34,6 +34,6 @@
34
34
  "koishi-plugin-cron": "^3.1.0",
35
35
  "mwn": "^3.0.3",
36
36
  "node-fetch": "^3.3.2",
37
- "pinyin-pro": "^3.28.1"
37
+ "pinyin-pro": "^3.29.1"
38
38
  }
39
39
  }