@easyops-cn/docusaurus-search-local 0.49.0 → 0.49.2
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/CHANGELOG.md +15 -0
- package/dist/client/client/utils/smartQueries.js +23 -17
- package/dist/locales/ja.json +12 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [0.49.2](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.49.1...v0.49.2) (2025-03-31)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* Add Japanese locale ([9a920db](https://github.com/easyops-cn/docusaurus-search-local/commit/9a920db9c91f4ce7f13227c8109874e5deec9d21))
|
|
11
|
+
|
|
12
|
+
## [0.49.1](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.49.0...v0.49.1) (2025-03-12)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* refine fuzzy matching order ([60d2b0b](https://github.com/easyops-cn/docusaurus-search-local/commit/60d2b0bab03ebcb9d969ac0fabaf2deaa76eef13)), closes [#504](https://github.com/easyops-cn/docusaurus-search-local/issues/504)
|
|
18
|
+
* refine fuzzy matching order ([#507](https://github.com/easyops-cn/docusaurus-search-local/issues/507)) ([646b5a0](https://github.com/easyops-cn/docusaurus-search-local/commit/646b5a0fb20933c86972047ec940a51270bf96ba)), closes [#504](https://github.com/easyops-cn/docusaurus-search-local/issues/504)
|
|
19
|
+
|
|
5
20
|
## [0.49.0](https://github.com/easyops-cn/docusaurus-search-local/compare/v0.48.5...v0.49.0) (2025-03-12)
|
|
6
21
|
|
|
7
22
|
|
|
@@ -76,37 +76,40 @@ export function smartQueries(tokens, zhDictionary) {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
: [], getQueriesMaybeTyping(extraTerms), fuzzyMatchingDistance > 0
|
|
82
|
-
? getQueriesMaybeTyping(extraTerms, fuzzyMatchingDistance)
|
|
83
|
-
: []);
|
|
79
|
+
const distance = Math.max(0, fuzzyMatchingDistance);
|
|
80
|
+
return getDistanceMatrix(terms, distance).concat(getDistanceMatrix(extraTerms, distance));
|
|
84
81
|
}
|
|
85
82
|
function getQueriesMaybeTyping(terms, editDistance) {
|
|
86
|
-
return termsToQueries(terms,
|
|
83
|
+
return termsToQueries(terms, editDistance).concat(termsToQueries(
|
|
87
84
|
// Ignore terms whose last token already has a trailing wildcard,
|
|
88
85
|
// or the last token is not `maybeTyping`.
|
|
89
86
|
terms.filter((term) => {
|
|
90
87
|
const token = term[term.length - 1];
|
|
91
88
|
return !token.trailing && token.maybeTyping;
|
|
92
|
-
}),
|
|
89
|
+
}), editDistance, true));
|
|
93
90
|
}
|
|
94
|
-
function termsToQueries(terms,
|
|
91
|
+
function termsToQueries(terms, editDistance, maybeTyping) {
|
|
95
92
|
return terms.flatMap((term) => {
|
|
96
93
|
const query = {
|
|
97
94
|
tokens: term.map((item) => item.value),
|
|
98
|
-
term: term.map((item) =>
|
|
99
|
-
value: item.value,
|
|
100
|
-
presence: lunr.Query.presence.REQUIRED,
|
|
95
|
+
term: term.map((item) => {
|
|
101
96
|
// The last token of a term maybe incomplete while user is typing.
|
|
102
97
|
// So append more queries with trailing wildcard added.
|
|
103
|
-
|
|
104
|
-
?
|
|
105
|
-
:
|
|
106
|
-
|
|
98
|
+
const trailing = maybeTyping
|
|
99
|
+
? item.trailing || item.maybeTyping
|
|
100
|
+
: item.trailing;
|
|
101
|
+
const distance = editDistance > 0 && item.value.length > editDistance
|
|
107
102
|
? editDistance
|
|
108
|
-
: undefined
|
|
109
|
-
|
|
103
|
+
: undefined;
|
|
104
|
+
return {
|
|
105
|
+
value: item.value,
|
|
106
|
+
presence: lunr.Query.presence.REQUIRED,
|
|
107
|
+
wildcard: trailing
|
|
108
|
+
? lunr.Query.wildcard.TRAILING
|
|
109
|
+
: lunr.Query.wildcard.NONE,
|
|
110
|
+
editDistance: distance,
|
|
111
|
+
};
|
|
112
|
+
}),
|
|
110
113
|
};
|
|
111
114
|
// Ignore queries that all terms ignored edit distance due to too short tokens.
|
|
112
115
|
if (editDistance && query.term.every((item) => !item.editDistance)) {
|
|
@@ -115,3 +118,6 @@ function termsToQueries(terms, maybeTyping, editDistance) {
|
|
|
115
118
|
return query;
|
|
116
119
|
});
|
|
117
120
|
}
|
|
121
|
+
function getDistanceMatrix(terms, distance) {
|
|
122
|
+
return Array.from({ length: distance + 1 }, (_, i) => getQueriesMaybeTyping(terms, i)).flat();
|
|
123
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"theme.SearchBar.label": "検索",
|
|
3
|
+
"theme.SearchBar.seeAll": "すべての結果を見る",
|
|
4
|
+
"theme.SearchBar.noResultsText": "結果が見つかりません。",
|
|
5
|
+
"theme.SearchBar.searchInContext": "「{context}」のすべての結果を見る",
|
|
6
|
+
"theme.SearchBar.seeAllOutsideContext": "「{context}」以外のすべての結果を見る",
|
|
7
|
+
"theme.SearchPage.existingResultsTitle": "検索:{query}",
|
|
8
|
+
"theme.SearchPage.emptyResultsTitle": "検索したい語句を入力してください。",
|
|
9
|
+
"theme.SearchPage.documentsFound.plurals": "検索数:{count}件",
|
|
10
|
+
"theme.SearchPage.noResultsText": "結果が見つかりません。",
|
|
11
|
+
"theme.SearchPage.searchContext.everywhere": "すべての場所"
|
|
12
|
+
}
|