@btst/plugin-search 1.1.0 → 1.1.1

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.
@@ -8,7 +8,7 @@ function normalizeSearchText(value) {
8
8
  }
9
9
  function searchRelevance(result, query) {
10
10
  const q = normalizeSearchText(query);
11
- if (!q) return 7;
11
+ if (!q) return 9;
12
12
  const title = normalizeSearchText(result.title);
13
13
  const aliases = result.aliases?.map(normalizeSearchText) ?? [];
14
14
  if (title === q) return 0;
@@ -17,7 +17,16 @@ function searchRelevance(result, query) {
17
17
  if (aliases.some((alias) => alias.startsWith(q))) return 3;
18
18
  if (title.includes(q)) return 4;
19
19
  if (aliases.some((alias) => alias.includes(q))) return 5;
20
- return normalizeSearchText(result.snippet).includes(q) ? 6 : 7;
20
+ const terms = [
21
+ ...new Set(query.split(/\s+/).map(normalizeSearchText).filter(Boolean))
22
+ ];
23
+ const containsTerms = (value) => {
24
+ const words = value.split(/\s+/).map(normalizeSearchText);
25
+ return terms.every((term) => words.some((word) => word.includes(term)));
26
+ };
27
+ if (containsTerms(result.title)) return 6;
28
+ if (result.aliases?.some(containsTerms)) return 7;
29
+ return normalizeSearchText(result.snippet).includes(q) ? 8 : 9;
21
30
  }
22
31
  function destination(basePath, slug) {
23
32
  return `${basePath.replace(/\/$/, "")}/${encodeURIComponent(slug)}`;
@@ -6,7 +6,7 @@ function normalizeSearchText(value) {
6
6
  }
7
7
  function searchRelevance(result, query) {
8
8
  const q = normalizeSearchText(query);
9
- if (!q) return 7;
9
+ if (!q) return 9;
10
10
  const title = normalizeSearchText(result.title);
11
11
  const aliases = result.aliases?.map(normalizeSearchText) ?? [];
12
12
  if (title === q) return 0;
@@ -15,7 +15,16 @@ function searchRelevance(result, query) {
15
15
  if (aliases.some((alias) => alias.startsWith(q))) return 3;
16
16
  if (title.includes(q)) return 4;
17
17
  if (aliases.some((alias) => alias.includes(q))) return 5;
18
- return normalizeSearchText(result.snippet).includes(q) ? 6 : 7;
18
+ const terms = [
19
+ ...new Set(query.split(/\s+/).map(normalizeSearchText).filter(Boolean))
20
+ ];
21
+ const containsTerms = (value) => {
22
+ const words = value.split(/\s+/).map(normalizeSearchText);
23
+ return terms.every((term) => words.some((word) => word.includes(term)));
24
+ };
25
+ if (containsTerms(result.title)) return 6;
26
+ if (result.aliases?.some(containsTerms)) return 7;
27
+ return normalizeSearchText(result.snippet).includes(q) ? 8 : 9;
19
28
  }
20
29
  function destination(basePath, slug) {
21
30
  return `${basePath.replace(/\/$/, "")}/${encodeURIComponent(slug)}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btst/plugin-search",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -175,7 +175,7 @@
175
175
  "@btst/stack": "6.2.2",
176
176
  "@workspace/ui": "0.0.0"
177
177
  },
178
- "gitHead": "ec8f741a6722d46974cd2e81034fa8a1a49cf531",
178
+ "gitHead": "22f6a7ebcacd239b935da7a580e19b1061a1b0b1",
179
179
  "scripts": {
180
180
  "build": "unbuild --clean",
181
181
  "typecheck": "tsc --project tsconfig.json",