@findlane/server 0.1.1 → 0.3.0

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/README.md CHANGED
@@ -44,7 +44,7 @@ The workspace ID is under Settings in the dashboard, and keys are under API keys
44
44
  | `delete(objectID)` | Delete a record. |
45
45
  | `getRecord(objectID)` | A record and its version. |
46
46
  | `upsertOne(record, { expectedVersion })`, `deleteOne(objectID, { expectedVersion })` | Write only if the record is still at `expectedVersion` (0 for one that never existed); retried with one idempotency key. |
47
- | `getSettings()`, `replaceSettings(settings)`, `waitForSettings()` | Read and change searchable fields, facets, filters, sorts, custom ranking, synonyms, typo tolerance, and text normalization. |
47
+ | `getSettings()`, `replaceSettings(settings)`, `waitForSettings()` | Read and change searchable fields, facets, filters, sorts, custom ranking, synonyms, languages, typo tolerance, and text normalization. |
48
48
  | `getIndexingStatus()`, `waitUntilIndexed(revision)` | Writes return an accepted revision and are searchable when accepted, so `waitUntilIndexed` returns at once. |
49
49
  | `getPublicSearchAccess()`, `setPublicSearchPolicy(policy)`, `usePublicIndexDefaults()` | Restrict what browser search may read and query. |
50
50
 
package/dist/index.d.ts CHANGED
@@ -26,6 +26,11 @@ export type IndexSettings = {
26
26
  customRanking?: SortRule[];
27
27
  /** Groups of interchangeable words or phrases (up to four words each). */
28
28
  synonyms?: string[][];
29
+ /** Languages whose common words queries drop, and whose plurals and alternative spellings match. */
30
+ languages?: Array<"da" | "de" | "en" | "is" | "no" | "sv">;
31
+ /** Searches say which words typo tolerance corrected, and `suggest()` offers a corrected query for a
32
+ * search that finds nothing. Off by default. */
33
+ didYouMean?: boolean;
29
34
  normalizationProfile?: "default-v2" | "default-v1" | "icelandic-ascii-v1";
30
35
  [key: string]: unknown;
31
36
  };
@@ -91,6 +96,9 @@ export type SearchRequest = {
91
96
  /** Field values to keep: a value, `{ in: [...] }`, or a range `{ gte, lte }` for numbers and dates. */
92
97
  filters?: Record<string, unknown>;
93
98
  facets?: string[];
99
+ /** Facets (also in `facets`) counted without the filter on their own field, so a list of choices
100
+ * keeps its other values, with counts, after one is chosen. */
101
+ disjunctiveFacets?: string[];
94
102
  limit?: number;
95
103
  offset?: number;
96
104
  attributesToRetrieve?: string[];
@@ -120,6 +128,20 @@ export type SearchResponse<T> = {
120
128
  facets: Record<string, Record<string, number>>;
121
129
  tookMs: number;
122
130
  sort?: string;
131
+ /** With the index's `didYouMean` setting: the query with the words typo tolerance corrected, when the
132
+ * results matched some words only by typo ("Showing results for …"), else null. */
133
+ didYouMean?: DidYouMean | null;
134
+ };
135
+ /** A corrected query. `applied`: the results are already for `q` (a search's "Showing results for");
136
+ * otherwise searching `q` finds results that the query didn't ("Did you mean"). `changes` lists each
137
+ * changed part of the query as typed. */
138
+ export type DidYouMean = {
139
+ q: string;
140
+ applied: boolean;
141
+ changes: {
142
+ from: string;
143
+ to: string;
144
+ }[];
123
145
  };
124
146
  export type ConditionalWriteOptions = {
125
147
  expectedVersion: number;
@@ -176,6 +198,10 @@ export declare class SearchServerClient {
176
198
  } = JsonRecord>(name: string): {
177
199
  /** Searches the index; the API key needs the `search` scope. */
178
200
  search: <R = T>(query?: SearchRequest, signal?: AbortSignal) => Promise<SearchResponse<R>>;
201
+ /** Did you mean: for a search that found nothing, a query that finds something, or null. Takes the
202
+ * same request (its q, filters, and fields matter). Needs the `didYouMean` setting; not counted as
203
+ * a search. */
204
+ suggest: (query: SearchRequest, signal?: AbortSignal) => Promise<DidYouMean | null>;
179
205
  upsert: (records: T[], signal?: AbortSignal) => Promise<WriteReceipt>;
180
206
  getRecord: (objectID: string, signal?: AbortSignal) => Promise<RecordSnapshot<T>>;
181
207
  upsertOne: (record: T, options: ConditionalWriteOptions) => Promise<WriteReceipt>;
package/dist/index.js CHANGED
@@ -97,6 +97,7 @@ class SearchServerClient {
97
97
  };
98
98
  return {
99
99
  search: (query = {}, signal) => request("/search", "POST", query, signal),
100
+ suggest: async (query, signal) => (await request("/suggest", "POST", query, signal)).didYouMean,
100
101
  upsert: (records, signal) => request("/records", "POST", { records }, signal),
101
102
  getRecord: (objectID, signal) => request(`/records/${encodeURIComponent(objectID)}`, "GET", undefined, signal),
102
103
  upsertOne: (record, options) => writeOne("upsert", record.objectID, record, options),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@findlane/server",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "Findlane server SDK: upload catalogs, manage index settings, and search with a secret workspace API key.",
5
5
  "keywords": ["findlane", "search", "full-text search", "typo tolerance", "ecommerce search", "search api", "sdk"],
6
6
  "license": "MIT",