@@ -307,14 +307,14 @@ client.setThrottleTime(500);
307307```
308308
309309## Indexing API
310- The Indexing API allows for retrieving documents, creating documents, updating single documents and batches of
311- documents, as well as deleting single documents and batches of documents.
310+ With the Indexing API, you can fetch, create, update, and delete single documents or
311+ batches of documents.
312312
313- Following indexing API functions are meant to be used in Node.js. Never expose your
314- secret key in your website code.
313+ Indexing API functions are meant to be used with Node.js. Never expose secret key in your
314+ website code.
315315
316316``` js
317- // Create client with your 32-character keys
317+ // Create client with your keys
318318var client = new AddSearchClient (' YOUR PUBLIC SITEKEY' , ' YOUR SECRET KEY' );
319319```
320320
@@ -323,42 +323,25 @@ Always keep the key secret.
323323
324324All Indexing API functions are Promise-based.
325325
326+ ### Document structure
327+ Documents can contain a set of pre-defined fields, as well as any number of custom fields
328+ defined under the custom_fields key.
326329
327- ### Document ID
328-
329- Document ID can be defined by the user, or it can be autogenerated when a document is added to the index.
330-
331- ``` js
332- // ID defined by the user
333- const docWithDefinedId = {
334- id: ' 1234' ,
335- custom_fields: {}
336- }
337-
338- // ID created from the URL field (md5 sum)
339- const docWithURL = {
340- url: ' https://..' , // id will be md5('https://..')
341- custom_fields: {}
342- }
343-
344- // ID will be generated automatically
345- const docWithAutogeneratedId = {
346- // No id or url fields
347- custom_fields: {}
348- }
349- ```
350-
330+ Using pre-defined fields is optional, but default [ Search UI] ( https://github.com/AddSearch/search-ui ) components
331+ display them by default, so they give you visible results faster.
351332
352- ### Document structure
353- Documents have schemaless data structures. Data fields should be defined under custom_fields key.
333+ Pre-defined fields are: url, title, h1, h2, language, title, main_content, and meta_description.
354334
335+ Example document:
355336``` js
356- // Create client with your 32-character keys
357337const doc = {
358338 id: ' 1234' ,
339+ url: ' https://www.example-store.com/product-x' ,
340+ title: ' Example product' ,
341+ language: ' en' ,
359342 custom_fields: {
360343 ' name' : ' Example product' ,
361- ' description' : ' Description for example product' ,
344+ ' description' : ' Description for the example product' ,
362345 ' price_cents' : 599 ,
363346 ' average_customer_rating' : 4.5 ,
364347 ' release_date' : 1589200255
@@ -374,9 +357,35 @@ Data types for custom fields are automatically detected from the content. Suppor
374357
375358Dates should be defined as UNIX timestamps with integer values.
376359
360+ ### Document ID
361+
362+ If the id field is not defined in the document, it is generated automatically either randomly
363+ or from the URL field, when the document is added to the index.
364+
365+ ``` js
366+ // ID defined by the user
367+ const docWithDefinedId = {
368+ id: ' 1234' ,
369+ custom_fields: {}
370+ }
371+ ```
372+ ``` js
373+ // ID created from the URL field (md5 sum)
374+ const docWithURL = {
375+ url: ' https://..' , // id will be md5('https://..')
376+ custom_fields: {}
377+ }
378+ ```
379+ ``` js
380+ // ID generated randomly
381+ const docWithAutogeneratedId = {
382+ // No id or url fields
383+ custom_fields: {}
384+ }
385+ ```
377386
378387### Save document
379- Add or update a document in the index.
388+ Add a document to the index, or update a document .
380389
381390``` js
382391const doc = {
@@ -398,6 +407,7 @@ client.saveDocument(doc)
398407
399408
400409### Get document by ID
410+ Fetch a specific document by ID.
401411``` js
402412client .getDocument (id)
403413 .then (response => {
@@ -410,6 +420,7 @@ client.getDocument(id)
410420
411421
412422### Delete document by ID
423+ Delete a specific document by ID.
413424``` js
414425client .deleteDocument (id)
415426 .then (response => {
@@ -422,6 +433,7 @@ client.deleteDocument(id)
422433
423434
424435### Save batch of documents
436+ Add or update bunch of documents defined in an array.
425437``` js
426438const batch = {
427439 documents: [
@@ -452,6 +464,7 @@ client.saveDocumentsBatch(batch)
452464
453465
454466### Delete batch of documents
467+ Delete multiple documents with an array of document IDs.
455468``` js
456469// Array of document IDs
457470const batch = {
@@ -469,7 +482,7 @@ client.deleteDocumentsBatch(batch)
469482```
470483
471484
472- ## Supported web browsers and node.js versions
485+ ## Supported browsers
473486The client is tested on
474487- Chrome
475488- Firefox
0 commit comments