@openfoodfacts/openfoodfacts-nodejs
    Preparing search index...

    Class SearchApi

    Index

    Constructors

    • Parameters

      • fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>
          • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
          • Parameters

            • input: RequestInfo | URL
            • Optionalinit: RequestInit

            Returns Promise<Response>

      • options: { baseUrl: string } = ...

      Returns SearchApi

    Methods

    • Parameters

      • query: {
            fuzziness?: number | null;
            index_id?: string | null;
            lang?: string;
            q: string;
            size?: number;
            taxonomy_names: string;
        }
        • Optionalfuzziness?: number | null

          Fuzziness level to use, default to no fuzziness.

        • Optionalindex_id?: string | null

          Index ID to use for the search, if not provided, the default index is used. If there is only one index, this parameter is not needed.

        • Optionallang?: string

          Language to search in, defaults to 'en'.

        • q: string

          User autocomplete query.

        • Optionalsize?: number

          Number of results to return.

        • taxonomy_names: string

          Name(s) of the taxonomy to search in, as a comma-separated value.

      Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: undefined;
                      header?: undefined;
                      path?: undefined;
                      query: {
                          fuzziness?: number
                          | null;
                          index_id?: string | null;
                          lang?: string;
                          q: string;
                          size?: number;
                          taxonomy_names: string;
                      };
                  };
                  requestBody?: undefined;
                  responses: {
                      "200": {
                          content: { "application/json": unknown };
                          headers: { [name: string]: unknown };
                      };
                      "422": {
                          content: {
                              "application/json": {
                                  detail?: { loc: (...)[]; msg: string; type: string }[];
                              };
                          };
                          headers: { [name: string]: unknown };
                      };
                  };
              },
              {
                  params: {
                      query: {
                          fuzziness?: number
                          | null;
                          index_id?: string | null;
                          lang?: string;
                          q: string;
                          size?: number;
                          taxonomy_names: string;
                      };
                  };
              },
              `${string}/${string}`,
          >,
      >

    • Parameters

      • identifier: string
      • Optionalquery: { index_id?: string | null }
        • Optionalindex_id?: string | null

          Index ID to use for the search, if not provided, the default index is used. If there is only one index, this parameter is not needed.

      Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: undefined;
                      header?: undefined;
                      path: { identifier: string };
                      query?: { index_id?: string | null };
                  };
                  requestBody?: undefined;
                  responses: {
                      "200": {
                          content: { "application/json": unknown };
                          headers: { [name: string]: unknown };
                      };
                      "422": {
                          content: {
                              "application/json": {
                                  detail?: { loc: (...)[]; msg: string; type: string }[];
                              };
                          };
                          headers: { [name: string]: unknown };
                      };
                  };
              },
              {
                  params: {
                      path: { identifier: string };
                      query: { index_id?: string | null } | undefined;
                  };
              },
              `${string}/${string}`,
          >,
      >

    • Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: undefined;
                      header?: undefined;
                      path?: undefined;
                      query?: undefined;
                  };
                  requestBody?: undefined;
                  responses: {
                      "200": {
                          content: { "text/html": string };
                          headers: { [name: string]: unknown };
                      };
                  };
              },
              {},
              `${string}/${string}`,
          >,
      >

    • Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: undefined;
                      header?: undefined;
                      path?: undefined;
                      query?: undefined;
                  };
                  requestBody?: undefined;
                  responses: {
                      "200": {
                          content: { "text/plain": string };
                          headers: { [name: string]: unknown };
                      };
                  };
              },
              {},
              `${string}/${string}`,
          >,
      >

    • Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: undefined;
                      header?: undefined;
                      path?: undefined;
                      query?: undefined;
                  };
                  requestBody?: undefined;
                  responses: {
                      "200": {
                          content: { "application/json": unknown };
                          headers: { [name: string]: unknown };
                      };
                  };
              },
              {},
              `${string}/${string}`,
          >,
      >

    • Parameters

      • Optionalquery: {
            display_debug?: boolean;
            index_id?: string | null;
            langs?: string;
            page?: number;
            page_size?: number;
            q?: string | null;
            sort_by?: string | null;
        }
        • Optionaldisplay_debug?: boolean
        • Optionalindex_id?: string | null

          Index ID to use for the search, if not provided, the default index is used. If there is only one index, this parameter is not needed.

        • Optionallangs?: string
        • Optionalpage?: number
        • Optionalpage_size?: number
        • Optionalq?: string | null
        • Optionalsort_by?: string | null

      Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: undefined;
                      header?: undefined;
                      path?: undefined;
                      query?: {
                          display_debug?: boolean;
                          index_id?: string
                          | null;
                          langs?: string;
                          page?: number;
                          page_size?: number;
                          q?: string | null;
                          sort_by?: string | null;
                      };
                  };
                  requestBody?: undefined;
                  responses: {
                      "200": {
                          content: { "text/html": string };
                          headers: { [name: string]: unknown };
                      };
                      "422": {
                          content: {
                              "application/json": {
                                  detail?: { loc: (...)[]; msg: string; type: string }[];
                              };
                          };
                          headers: { [name: string]: unknown };
                      };
                  };
              },
              {
                  params: {
                      query: | {
                          display_debug?: boolean;
                          index_id?: string
                          | null;
                          langs?: string;
                          page?: number;
                          page_size?: number;
                          q?: string | null;
                          sort_by?: string | null;
                      }
                      | undefined;
                  };
              },
              `${string}/${string}`,
          >,
      >

    • Parameters

      Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: undefined;
                      header?: undefined;
                      path?: undefined;
                      query?: undefined;
                  };
                  requestBody: {
                      content: {
                          "application/json": {
                              charts?: | (
                                  | { chart_type: "DistributionChartType"; field: string }
                                  | { chart_type: "ScatterChartType"; x: string; y: string }
                              )[]
                              | null;
                              facets?: string[] | null;
                              fields?: string[] | null;
                              index_id?: string | null;
                              langs: string[];
                              page: number;
                              page_size: number;
                              q?: string | null;
                              sort_by?: string | null;
                              sort_params?: Record<string, unknown> | null;
                          };
                      };
                  };
                  responses: {
                      "200": {
                          content: { "application/json": unknown };
                          headers: { [name: string]: unknown };
                      };
                      "422": {
                          content: {
                              "application/json": {
                                  detail?: { loc: (...)[]; msg: string; type: string }[];
                              };
                          };
                          headers: { [name: string]: unknown };
                      };
                  };
              },
              {
                  body: {
                      charts?: | (
                          | { chart_type: "DistributionChartType"; field: string }
                          | { chart_type: "ScatterChartType"; x: string; y: string }
                      )[]
                      | null;
                      facets?: string[] | null;
                      fields?: string[] | null;
                      index_id?: string | null;
                      langs: string[];
                      page: number;
                      page_size: number;
                      q?: string | null;
                      sort_by?: string | null;
                      sort_params?: Record<string, unknown> | null;
                  };
              },
              `${string}/${string}`,
          >,
      >

    • Parameters

      • query:
            | {
                charts?: string;
                facets?: string;
                fields?: string;
                index_id?: string
                | null;
                langs?: string;
                page?: number;
                page_size?: number;
                q?: string | null;
                sort_by?: string | null;
            }
            | undefined
        • {
              charts?: string;
              facets?: string;
              fields?: string;
              index_id?: string | null;
              langs?: string;
              page?: number;
              page_size?: number;
              q?: string | null;
              sort_by?: string | null;
          }
          • Optionalcharts?: string

            Name of vega representations to return in the response. Can be distribution chart or scatter plot

          • Optionalfacets?: string

            Name of facets to return in the response as a comma-separated value. If None (default) no facets are returned.

          • Optionalfields?: string

            List of fields to include in the response. All other fields will be ignored.

          • Optionalindex_id?: string | null

            Index ID to use for the search, if not provided, the default index is used. If there is only one index, this parameter is not needed.

          • Optionallangs?: string

            List of languages we want to support during search. This list should include the user expected language, and additional languages (such as english for example).

            This is currently used for language-specific subfields to choose in which
            subfields we're searching in.
            
            If not provided, `['en']` is used.
            
          • Optionalpage?: number

            Page to request, starts at 1.

          • Optionalpage_size?: number

            Number of results to return per page.

          • Optionalq?: string | null

            The search query, it supports Lucene search query syntax (https://lucene.apache.org/core/3_6_0/queryparsersyntax.html). Words that are not recognized by the lucene query parser are searched as full text search.

            Example: `categories_tags:"en:beverages" strawberry brands:"casino"` query use a
            filter clause for categories and brands and look for "strawberry" in multiple
            fields.
            
            The query is optional, but `sort_by` value must then be provided.
            
          • Optionalsort_by?: string | null

            Field name to use to sort results, the field should exist and be sortable. If it is not provided, results are sorted by descending relevance score.

            If you put a minus before the name, the results will be sorted by descending order.
            
            If the field name match a known script (defined in your configuration),
            it will be use for sorting.
            
            In this case you also need to provide additional parameters corresponding to your script parameters.
            If a script needs parameters, you can only use the POST method.
            
            Beware that this may have a big [impact on performance][perf_link]
            
            Also bare in mind [privacy considerations][privacy_link] if your script parameters contains sensible data.
            
            [perf_link]: https://openfoodfacts.github.io/search-a-licious/users/how-to-use-scripts/#performance-considerations
            [privacy_link]: https://openfoodfacts.github.io/search-a-licious/users/how-to-use-scripts/#performance-considerations
            
        • undefined

      Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: undefined;
                      header?: undefined;
                      path?: undefined;
                      query?: {
                          charts?: string;
                          facets?: string;
                          fields?: string;
                          index_id?: string
                          | null;
                          langs?: string;
                          page?: number;
                          page_size?: number;
                          q?: string | null;
                          sort_by?: string | null;
                      };
                  };
                  requestBody?: undefined;
                  responses: {
                      "200": {
                          content: {
                              "application/json": | {
                                  debug: { query: Record<string, unknown> };
                                  errors: { description?: (...) | (...) | (...); title: string }[];
                              }
                              | {
                                  aggregations?: Record<string, unknown>
                                  | null;
                                  charts?: { [key: string]: Record<(...), (...)> } | null;
                                  count: number;
                                  debug: { query: Record<string, unknown> };
                                  facets?:
                                      | {
                                          [key: string]: {
                                              count_error_margin?: ...;
                                              items: ...;
                                              name: ...;
                                          };
                                      }
                                      | null;
                                  hits: Record<string, unknown>[];
                                  is_count_exact: boolean;
                                  page: number;
                                  page_count: number;
                                  page_size: number;
                                  timed_out: boolean;
                                  took: number;
                                  warnings?: { description?: ...; title: ... }[] | null;
                              };
                          };
                          headers: { [name: string]: unknown };
                      };
                      "422": {
                          content: {
                              "application/json": {
                                  detail?: { loc: (...)[]; msg: string; type: string }[];
                              };
                          };
                          headers: { [name: string]: unknown };
                      };
                  };
              },
              {
                  params: {
                      query: | {
                          charts?: string;
                          facets?: string;
                          fields?: string;
                          index_id?: string
                          | null;
                          langs?: string;
                          page?: number;
                          page_size?: number;
                          q?: string | null;
                          sort_by?: string | null;
                      }
                      | undefined;
                  };
              },
              `${string}/${string}`,
          >,
      >