@findlane/server 0.2.0 → 0.4.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/dist/index.d.ts CHANGED
@@ -28,6 +28,9 @@ export type IndexSettings = {
28
28
  synonyms?: string[][];
29
29
  /** Languages whose common words queries drop, and whose plurals and alternative spellings match. */
30
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;
31
34
  normalizationProfile?: "default-v2" | "default-v1" | "icelandic-ascii-v1";
32
35
  [key: string]: unknown;
33
36
  };
@@ -93,6 +96,12 @@ export type SearchRequest = {
93
96
  /** Field values to keep: a value, `{ in: [...] }`, or a range `{ gte, lte }` for numbers and dates. */
94
97
  filters?: Record<string, unknown>;
95
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[];
102
+ /** Number fields (up to eight) whose smallest and largest values across the matches to return in
103
+ * `facetStats`, such as a price slider's bounds. Each field's own filter is left out. */
104
+ facetStats?: string[];
96
105
  limit?: number;
97
106
  offset?: number;
98
107
  attributesToRetrieve?: string[];
@@ -120,8 +129,28 @@ export type SearchResponse<T> = {
120
129
  totalRelation?: "eq" | "gte";
121
130
  hasMore?: boolean;
122
131
  facets: Record<string, Record<string, number>>;
132
+ /** With `facetStats`: each field's smallest and largest value across the matches, without the field's
133
+ * own filter. A field no match has is left out. */
134
+ facetStats?: Record<string, {
135
+ min: number;
136
+ max: number;
137
+ }>;
123
138
  tookMs: number;
124
139
  sort?: string;
140
+ /** With the index's `didYouMean` setting: the query with the words typo tolerance corrected, when the
141
+ * results matched some words only by typo ("Showing results for …"), else null. */
142
+ didYouMean?: DidYouMean | null;
143
+ };
144
+ /** A corrected query. `applied`: the results are already for `q` (a search's "Showing results for");
145
+ * otherwise searching `q` finds results that the query didn't ("Did you mean"). `changes` lists each
146
+ * changed part of the query as typed. */
147
+ export type DidYouMean = {
148
+ q: string;
149
+ applied: boolean;
150
+ changes: {
151
+ from: string;
152
+ to: string;
153
+ }[];
125
154
  };
126
155
  export type ConditionalWriteOptions = {
127
156
  expectedVersion: number;
@@ -178,6 +207,10 @@ export declare class SearchServerClient {
178
207
  } = JsonRecord>(name: string): {
179
208
  /** Searches the index; the API key needs the `search` scope. */
180
209
  search: <R = T>(query?: SearchRequest, signal?: AbortSignal) => Promise<SearchResponse<R>>;
210
+ /** Did you mean: for a search that found nothing, a query that finds something, or null. Takes the
211
+ * same request (its q, filters, and fields matter). Needs the `didYouMean` setting; not counted as
212
+ * a search. */
213
+ suggest: (query: SearchRequest, signal?: AbortSignal) => Promise<DidYouMean | null>;
181
214
  upsert: (records: T[], signal?: AbortSignal) => Promise<WriteReceipt>;
182
215
  getRecord: (objectID: string, signal?: AbortSignal) => Promise<RecordSnapshot<T>>;
183
216
  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.2.0",
3
+ "version": "0.4.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",