0.0.3 • Published 4 years ago

@yashatreya/re-search-js v0.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

re-search-js

Installation

npm install @yashatreya/re-search-js

Usage

const ReSearch = require('re-search');

const client = new ReSearch('projectID', 'admin-apiKey','indexName');

Methods

/**
 *  Method 1: addSchema()
 *  Equivalent to the `SCHEMA` argument in `FT.CREATE` command of the redis search
 *  This helps the search API know which fields to search from.
 * 
 *  SchemaFieldObject: {
 *    type: 'TEXT' | 'NUMERIC'
 *    field: 'fieldName'
 *    sortable: boolean
 *  }
 * 
 *  client.addSchema(array: SchemaFieldObject[])
 *  Takes array of objects as parameter
 */ 

/**
 * @param {array} array - array of objects
 * @return Promise
 */

client.addSchema([
    {
        type: 'TEXT',
        field: 'fieldName',
        sortable: true,
    },
    {
        type: 'NUMERIC',
        field: 'fieldName',
        sortable: true,
    },
    {
        type: 'NUMERIC',
        field: 'fieldName',
        sortable: true,
    }
]);

/**
 *  Method 2: saveObjects
 *  data = {
 *    objectID: 'string' - This is a mandatory field which has the value of type string. It is a unique ID for your object
 *    [key]: [value]
 *    ....
 *  }
 *  client.saveObjects(array: data[]) - Takes array of objects as parameter
 * 
 *  Currently the saveObjects is limited to only 500 objects per request
 */

const array = require("randomArray.json");

/**
 * @param {array} array - array of objects
 * @return Promise
 */

client.saveObjects(array)

/**
 *  Method 3: removeObjects
 *  
 *  client.removeObjects(array: string[]) - Takes array of strings(objectIDs) as parameter
 * 
 *  @param {array} - array of objectID's
 *  @return Promise
 */
const arr = ['123', '2acfe', 'wvr345'];
client.removeObjects(arr);