@tinacms/search 1.0.4 → 1.0.6

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.
@@ -1,6 +1,6 @@
1
1
  export type { SearchClient } from './types';
2
2
  export { processDocumentForIndexing } from './indexer/utils';
3
- export declare const queryToSearchIndexQuery: (query: string) => any;
3
+ export declare const queryToSearchIndexQuery: (query: string, stopwordLanguages?: string[]) => any;
4
4
  export declare const optionsToSearchIndexOptions: (options?: {
5
5
  limit?: number;
6
6
  cursor?: string;
@@ -1,3 +1,4 @@
1
+ import * as sw from "stopword";
1
2
  class StringBuilder {
2
3
  constructor(limit) {
3
4
  this.length = 0;
@@ -116,13 +117,33 @@ const processDocumentForIndexing = (data, path, collection, textIndexLength, fie
116
117
  }
117
118
  return data;
118
119
  };
119
- const queryToSearchIndexQuery = (query) => {
120
+ const memo = {};
121
+ const lookupStopwords = (keys, defaultStopWords = sw.eng) => {
122
+ let stopwords = defaultStopWords;
123
+ if (keys) {
124
+ if (memo[keys.join(",")]) {
125
+ return memo[keys.join(",")];
126
+ }
127
+ stopwords = [];
128
+ for (const key of keys) {
129
+ stopwords.push(...sw[key]);
130
+ }
131
+ memo[keys.join(",")] = stopwords;
132
+ }
133
+ return stopwords;
134
+ };
135
+ const queryToSearchIndexQuery = (query, stopwordLanguages) => {
120
136
  let q;
121
137
  const parts = query.split(" ");
138
+ const stopwords = lookupStopwords(stopwordLanguages);
122
139
  if (parts.length === 1) {
123
140
  q = { AND: [parts[0]] };
124
141
  } else {
125
- q = { AND: parts.filter((part) => part.toLowerCase() !== "and") };
142
+ q = {
143
+ AND: parts.filter(
144
+ (part) => part.toLowerCase() !== "and" && stopwords.indexOf(part.toLowerCase()) === -1
145
+ )
146
+ };
126
147
  }
127
148
  return q;
128
149
  };
@@ -1,7 +1,24 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@tinacms/search"] = {}));
3
- })(this, function(exports2) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("stopword")) : typeof define === "function" && define.amd ? define(["exports", "stopword"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@tinacms/search"] = {}, global.NOOP));
3
+ })(this, function(exports2, sw) {
4
4
  "use strict";
5
+ function _interopNamespaceDefault(e) {
6
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
7
+ if (e) {
8
+ for (const k in e) {
9
+ if (k !== "default") {
10
+ const d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: () => e[k]
14
+ });
15
+ }
16
+ }
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+ const sw__namespace = /* @__PURE__ */ _interopNamespaceDefault(sw);
5
22
  class StringBuilder {
6
23
  constructor(limit) {
7
24
  this.length = 0;
@@ -120,13 +137,33 @@
120
137
  }
121
138
  return data;
122
139
  };
123
- const queryToSearchIndexQuery = (query) => {
140
+ const memo = {};
141
+ const lookupStopwords = (keys, defaultStopWords = sw__namespace.eng) => {
142
+ let stopwords = defaultStopWords;
143
+ if (keys) {
144
+ if (memo[keys.join(",")]) {
145
+ return memo[keys.join(",")];
146
+ }
147
+ stopwords = [];
148
+ for (const key of keys) {
149
+ stopwords.push(...sw__namespace[key]);
150
+ }
151
+ memo[keys.join(",")] = stopwords;
152
+ }
153
+ return stopwords;
154
+ };
155
+ const queryToSearchIndexQuery = (query, stopwordLanguages) => {
124
156
  let q;
125
157
  const parts = query.split(" ");
158
+ const stopwords = lookupStopwords(stopwordLanguages);
126
159
  if (parts.length === 1) {
127
160
  q = { AND: [parts[0]] };
128
161
  } else {
129
- q = { AND: parts.filter((part) => part.toLowerCase() !== "and") };
162
+ q = {
163
+ AND: parts.filter(
164
+ (part) => part.toLowerCase() !== "and" && stopwords.indexOf(part.toLowerCase()) === -1
165
+ )
166
+ };
130
167
  }
131
168
  return q;
132
169
  };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,4 @@ import si from 'search-index';
2
2
  export { SearchIndexer } from './indexer';
3
3
  export { LocalSearchIndexClient, TinaCMSSearchIndexClient } from './client';
4
4
  export type { SearchClient } from './types';
5
- export { default as sw } from 'stopword';
6
5
  export { si };
7
- export declare const lookupStopwords: (keys?: string[], defaultStopWords?: string[]) => string[];
package/dist/index.js CHANGED
@@ -28,18 +28,16 @@ __export(src_exports, {
28
28
  LocalSearchIndexClient: () => LocalSearchIndexClient,
29
29
  SearchIndexer: () => SearchIndexer,
30
30
  TinaCMSSearchIndexClient: () => TinaCMSSearchIndexClient,
31
- lookupStopwords: () => lookupStopwords,
32
- si: () => import_search_index2.default,
33
- sw: () => import_stopword.default
31
+ si: () => import_search_index2.default
34
32
  });
35
33
  module.exports = __toCommonJS(src_exports);
36
- var sw = __toESM(require("stopword"));
37
34
  var import_search_index2 = __toESM(require("search-index"));
38
35
 
39
36
  // src/indexer/index.ts
40
37
  var import_graphql = require("@tinacms/graphql");
41
38
 
42
39
  // src/indexer/utils.ts
40
+ var sw = __toESM(require("stopword"));
43
41
  var StringBuilder = class {
44
42
  constructor(limit) {
45
43
  this.length = 0;
@@ -158,6 +156,21 @@ var processDocumentForIndexing = (data, path, collection, textIndexLength, field
158
156
  }
159
157
  return data;
160
158
  };
159
+ var memo = {};
160
+ var lookupStopwords = (keys, defaultStopWords = sw.eng) => {
161
+ let stopwords = defaultStopWords;
162
+ if (keys) {
163
+ if (memo[keys.join(",")]) {
164
+ return memo[keys.join(",")];
165
+ }
166
+ stopwords = [];
167
+ for (const key of keys) {
168
+ stopwords.push(...sw[key]);
169
+ }
170
+ memo[keys.join(",")] = stopwords;
171
+ }
172
+ return stopwords;
173
+ };
161
174
 
162
175
  // src/indexer/index.ts
163
176
  var SearchIndexer = class {
@@ -345,25 +358,10 @@ ${await res.text()}`
345
358
  }
346
359
  }
347
360
  };
348
-
349
- // src/index.ts
350
- var import_stopword = __toESM(require("stopword"));
351
- var lookupStopwords = (keys, defaultStopWords = sw.eng) => {
352
- let stopwords = defaultStopWords;
353
- if (keys) {
354
- stopwords = [];
355
- for (const key of keys) {
356
- stopwords.push(...sw[key]);
357
- }
358
- }
359
- return stopwords;
360
- };
361
361
  // Annotate the CommonJS export names for ESM import in node:
362
362
  0 && (module.exports = {
363
363
  LocalSearchIndexClient,
364
364
  SearchIndexer,
365
365
  TinaCMSSearchIndexClient,
366
- lookupStopwords,
367
- si,
368
- sw
366
+ si
369
367
  });
@@ -1,2 +1,3 @@
1
1
  import { Collection, ObjectField } from '@tinacms/schema-tools';
2
2
  export declare const processDocumentForIndexing: (data: any, path: string, collection: Collection, textIndexLength: number, field?: ObjectField) => any;
3
+ export declare const lookupStopwords: (keys?: string[], defaultStopWords?: string[]) => string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/search",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index-client.es.js",
6
6
  "typings": "dist/index.d.ts",
@@ -29,8 +29,8 @@
29
29
  ]
30
30
  },
31
31
  "dependencies": {
32
- "@tinacms/graphql": "1.4.19",
33
- "@tinacms/schema-tools": "1.4.7",
32
+ "@tinacms/graphql": "1.4.21",
33
+ "@tinacms/schema-tools": "1.4.8",
34
34
  "abstract-level": "^1.0.3",
35
35
  "memory-level": "^1.0.0",
36
36
  "module-error": "^1.0.2",