The Search module provides methods for reading and writing record data to a workflow. The instance methods exposed by this class are available for use from within a running workflow. The following example uses search to set a name field and increment a counter field. The workflow returns the incremented value.

//searchWorkflow.ts
import { workflow } from '@hotmeshio/hotmesh';

export async function searchExample(name: string): Promise<{counter: number}> {
const search = await workflow.search();
await search.set({ name });
const newCounterValue = await search.incr('counter', 1);
return { counter: newCounterValue };
}

Methods

  • Deletes the fields provided as args. Returns the count of fields that were deleted.

    Parameters

    • Rest...args: string[]

    Returns Promise<number | void>

    const search = await workflow.search();
    const count = await search.del('field1', 'field2', 'field3');
  • Returns the value of the record data field, given a field id

    Parameters

    • id: string

    Returns Promise<string>

    const search = await workflow.search();
    const value = await search.get('field1');
  • Increments the value of a float field by the given amount. Returns the new value of the field after the increment. Pass a negative number to decrement the value.

    Parameters

    • key: string
    • val: number

    Returns Promise<number>

    const search = await workflow.search();
    const count = await search.incr('field1', 1.5);
  • Returns the values of all specified fields in the HASH stored at key.

    Parameters

    • Rest...args: string[]

    Returns Promise<string[]>

  • Multiplies the value of a field by the given amount. Returns the new value of the field after the multiplication. NOTE: this is exponential multiplication.

    Parameters

    • key: string
    • val: number

    Returns Promise<number>

    const search = await workflow.search();
    const product = await search.mult('field1', 1.5);
  • Sets the fields listed in args. Returns the count of new fields that were set (does not count fields that were updated)

    Parameters

    • Rest...args: any[]

    Returns Promise<number>

    const search = await workflow.search();
    const count = await search.set({ field1: 'value1', field2: 'value2' });
  • Returns an array of search indexes ids

    Parameters

    Returns Promise<string[]>

    const searchIndexes = await Search.listSearchIndexes(hotMeshClient);