Esposter
    Preparing search index...

    Class MockSearchClient<TModel>

    An in-memory mock of the Azure SearchClient. It uses a Map to simulate the search index and applies the same OData filtering as the other mock clients.

    const mockSearchClient = new MockSearchClient(SearchIndex.Messages);
    await mockSearchClient.uploadDocuments([{ ... }]);
    const { count, results } = await mockSearchClient.search("*", { filter, includeTotalCount: true });

    Type Parameters

    • TModel extends object = Record<string, unknown>

    Implements

    • Except<SearchClient<TModel>, "pipeline">
    Index

    Constructors

    • Type Parameters

      • TModel extends object = Record<string, unknown>

      Parameters

      • indexName: string

      Returns MockSearchClient<TModel>

    Properties

    apiVersion: string = ""

    The API version to use when communicating with the service.

    use {@Link serviceVersion} instead

    endpoint: string = MOCK_SEARCH_BASE_URL

    The endpoint of the search service

    indexName: string

    The name of the index

    serviceVersion: string = ""

    The service version to use when communicating with the service.

    Accessors

    • get documents(): object[]

      Returns object[]

    Methods

    • Based on a partial searchText from the user, return a list of potential completion strings based on a specified suggester.

      Returns Promise<AutocompleteResult>

      import { SearchClient, AzureKeyCredential, SearchFieldArray } from "@azure/search-documents";

      type TModel = {
      key: string;
      azure?: {
      sdk: string | null;
      } | null;
      };

      const client = new SearchClient<TModel>(
      "endpoint.azure",
      "indexName",
      new AzureKeyCredential("key"),
      );

      const searchFields: SearchFieldArray<TModel> = ["azure/sdk"];

      const autocompleteResult = await client.autocomplete("searchText", "suggesterName", {
      searchFields,
      });
    • Delete a set of documents.

      Parameters

      • documents: TModel[]

        Documents to be deleted.

      • Optionaloptions: IndexDocumentsOptions

        Additional options.

      Returns Promise<IndexDocumentsResult>

    • Delete a set of documents.

      Parameters

      • keyName: keyof TModel

        The name of their primary key in the index.

      • keyValues: string[]

        The primary key values of documents to delete.

      • Optionaloptions: IndexDocumentsOptions

        Additional options.

      Returns Promise<IndexDocumentsResult>

    • Retrieve a particular document from the index by key.

      Type Parameters

      • TFields extends string

      Parameters

      • _key: string
      • Optional_options: GetDocumentOptions<TModel, TFields>

      Returns Promise<NarrowedModel<TModel, TFields>>

    • Retrieves the number of documents in the index.

      Parameters

      • Optional_options: OperationOptions

      Returns Promise<number>

    • Perform a set of index modifications (upload, merge, mergeOrUpload, delete) for the given set of documents. This operation may partially succeed and not all document operations will be reflected in the index. If you would like to treat this as an exception, set the throwOnAnyFailure option to true. For more details about how merging works, see: https://learn.microsoft.com/rest/api/searchservice/AddUpdate-or-Delete-Documents

      Parameters

      • _batch: IndexDocumentsBatch<TModel>
      • Optional_options: IndexDocumentsOptions

      Returns Promise<IndexDocumentsResult>

    • Update a set of documents in the index.

      For more details about how merging works, see https://learn.microsoft.com/rest/api/searchservice/AddUpdate-or-Delete-Documents

      Parameters

      • _documents: TModel[]
      • Optional_options: IndexDocumentsOptions

      Returns Promise<IndexDocumentsResult>

    • Update a set of documents in the index or upload them if they don't exist.

      For more details about how merging works, see https://learn.microsoft.com/rest/api/searchservice/AddUpdate-or-Delete-Documents

      Parameters

      • _documents: TModel[]
      • Optional_options: IndexDocumentsOptions

      Returns Promise<IndexDocumentsResult>

    • Performs a search on the current index given the specified arguments.

      Type Parameters

      • TFields extends string

      Parameters

      • OptionalsearchText: string

        Text to search

      • Optionaloptions: SearchOptions<TModel, TFields>

        Options for the search operation.

      Returns Promise<SearchDocumentsResult<TModel, TFields>>

      import { SearchClient, AzureKeyCredential, SearchFieldArray } from "@azure/search-documents";

      type TModel = {
      key: string;
      azure?: {
      sdk: string | null;
      } | null;
      };

      const client = new SearchClient<TModel>(
      "endpoint.azure",
      "indexName",
      new AzureKeyCredential("key"),
      );

      const select = ["azure/sdk"] as const;
      const searchFields: SearchFieldArray<TModel> = ["azure/sdk"];

      const searchResult = await client.search("searchText", {
      select,
      searchFields,
      });
    • Returns a short list of suggestions based on the searchText and specified suggester.

      Type Parameters

      • TFields extends string = never

      Parameters

      • _searchText: string
      • _suggesterName: string
      • Optional_options: SuggestOptions<TModel, TFields>

      Returns Promise<SuggestDocumentsResult<TModel, TFields>>

      import { SearchClient, AzureKeyCredential, SearchFieldArray } from "@azure/search-documents";

      type TModel = {
      key: string;
      azure?: {
      sdk: string | null;
      } | null;
      };

      const client = new SearchClient<TModel>(
      "endpoint.azure",
      "indexName",
      new AzureKeyCredential("key"),
      );

      const select = ["azure/sdk"] as const;
      const searchFields: SearchFieldArray<TModel> = ["azure/sdk"];

      const suggestResult = await client.suggest("searchText", "suggesterName", {
      select,
      searchFields,
      });
    • Upload an array of documents to the index.

      Parameters

      • documents: TModel[]

        The documents to upload.

      • Optional_options: IndexDocumentsOptions

      Returns Promise<IndexDocumentsResult>