Skip to main content
Version: Current

Search Actions

  • os.eraseSearchCollection(recordName: string, address: string, options: RecordActionOptions): Promise<CrudEraseItemResult>

    Deletes a search collection along with all the documents in it.

    Returns a promise that resolves with the result of the operation.

    The first parameter is a string and is the name of the record to delete the search collection from.

    The second parameter is a string and is the address of the search collection to delete.

    The third parameter is a RecordActionOptions and is the options for the request.

    Examples
    Erase a search collection
    const result = await os.eraseSearchCollection('recordName', 'mySearchCollection');
  • os.eraseSearchDocument(recordName: string, address: string, documentId: string, options: RecordActionOptions): Promise<EraseDocumentResult>

    Erases a search document from the specified search collection in the given record.

    The first parameter is a string and is the name of the record that the search document is in.

    The second parameter is a string and is the address of the search collection that the document is in.

    The third parameter is a string and is the ID of the document that should be erased.

    The fourth parameter is a RecordActionOptions and is the options for the request.

    Examples
    Erase a search document
    const result = await os.eraseSearchDocument('myRecord', 'mySearchCollection', 'documentId');
  • os.getSearchCollection(recordName: string, address: string, options: RecordActionOptions): Promise<CrudGetItemResult>

    Gets a search collection from the specified record.

    The first parameter is a string and is the name of the record to retrieve the search collection from.

    The second parameter is a string and is the address of the search collection to retrieve.

    The third parameter is a RecordActionOptions and is the options for the request.

    Examples
    Get a search collection
    const result = await os.getSearchCollection('myRecord', 'mySearchCollection');
    Search through a search collection
    import Typesense from 'typesense';
    const collection = await os.getSearchCollection('myRecord', 'mySearchCollection');

    if (!collection.success) {
    os.toast('Failed to get search collection: ' + collection.errorMessage);
    return;
    }

    const client = new Typesense.Client({
    nodes: collection.item.nodes,
    apiKey: collection.item.searchApiKey,
    });

    const searchResults = await client.collections(collection.item.collectionName).documents().search({
    q: 'search term',
    query_by: 'title,description',
    sort_by: 'price:asc',
    });

    console.log('search results', searchResults);
  • os.listSearchCollections(recordName: string, startingAddress?: string, options: ListDataOptions): Promise<CrudListItemsResult>

    Lists the search collections in a record.

    Returns a promise that resolves with the result of the operation.

    The first parameter is a string and is the name of the record to delete the search collection from.

    The second parameter is optional and is a string and is the address that the listing should start after.

    The third parameter is a ListDataOptions and is the options for the request.

    Examples
    List search collections
    const result = await os.listSearchCollections('recordName', 'mySearchCollection');
  • os.listSearchCollectionsByMarker(recordName: string, marker: string, startingAddress?: string, options: ListDataOptions): Promise<CrudListItemsResult>

    Lists the search collections in a record by a specific marker.

    The first parameter is a string and is the name of the record to list the search collections from.

    The second parameter is a string and is the marker to filter the list by.

    The third parameter is optional and is a string and is the address that the listing should start after.

    The fourth parameter is a ListDataOptions and is the options for the request.

    Examples
    List public read search collections
    const result = await os.listSearchCollectionsByMarker('recordName', 'publicRead');
    List private search collections
    const result = await os.listSearchCollectionsByMarker('recordName', 'private');
  • os.recordSearchCollection(request: RecordSearchCollectionRequest, options: RecordActionOptions): Promise<CrudRecordItemResult>

    Creates or updates a search collection in the given record.

    Returns a promise that resolves with the result of the operation.

    The first parameter is a RecordSearchCollectionRequest and is the request to create or update the search collection.

    The second parameter is a RecordActionOptions and is the options for the request.

    Examples
    Record a search collection with an automatic schema
    const result = await os.recordSearchCollection({
    recordName: 'myRecord',
    address: 'mySearchCollection',
    schema: {
    '.*': {
    type: 'auto'
    }
    }
    });
    Record a search collection with a custom schema
    const result = await os.recordSearchCollection({
    recordName: 'myRecord',
    address: 'mySearchCollection',
    schema: {
    title: {
    type: 'string',
    },
    description: {
    type: 'string',
    },
    price: {
    type: 'int32',
    }
    }
    });
    Record a private search collection
    const result = await os.recordSearchCollection({
    recordName: 'myRecord',
    address: 'mySearchCollection',
    schema: {
    '.*': {
    type: 'auto'
    }
    },
    markers: ['private']
    });
    Record and search through a search collection
    import Typesense from 'typesense';
    const result = await os.recordSearchCollection({
    recordName: 'myRecord',
    address: 'mySearchCollection',
    schema: {
    '.*': {
    type: 'auto'
    }
    }
    });

    if (!result.success) {
    os.toast('Failed to record search collection: ' + result.errorMessage);
    return;
    }

    const collection = await os.getSearchCollection('myRecord', 'mySearchCollection');

    if (!collection.success) {
    os.toast('Failed to get search collection: ' + collection.errorMessage);
    return;
    }

    const client = new Typesense.Client({
    nodes: collection.item.nodes,
    apiKey: collection.item.searchApiKey,
    });

    const searchResults = await client.collections(collection.item.collectionName).documents().search({
    q: 'search term',
    query_by: 'title,description',
    sort_by: 'price:asc',
    });

    console.log('search results', searchResults);
  • os.recordSearchDocument(request: RecordSearchDocumentRequest, options: RecordActionOptions): Promise<StoreDocumentResult>

    Records a search document to the specified search collection in the given record.

    The first parameter is a RecordSearchDocumentRequest and is the request to record the search document.

    The second parameter is a RecordActionOptions and is the options for the request.

    Examples
    Record a search document
    const result = await os.recordSearchDocument({
    recordName: 'myRecord',
    address: 'mySearchCollection',
    document: {
    // ensure that the document matches the schema of the search collection
    title: 'My Document',
    description: 'This is the content of my document.'
    price: 10,
    }
    });