@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>;
            (input: string | Request | URL, init?: RequestInit): Promise<Response>;
        }
          • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
          • Parameters

            • input: RequestInfo | URL
            • Optionalinit: RequestInit

            Returns Promise<Response>

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

            • input: RequestInfo | URL
            • Optionalinit: RequestInit

            Returns Promise<Response>

          • (input: string | Request | URL, init?: RequestInit): Promise<Response>
          • Parameters

            • input: string | Request | URL
            • Optionalinit: RequestInit

            Returns Promise<Response>

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

      Returns SearchApi

    Methods

    • Parameters

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

          Fuzziness level to use, default to no fuzziness.

        • Optionalindex_id?: null | string

          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?: null
                          | number;
                          index_id?: null | string;
                          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?: null
                          | number;
                          index_id?: null | string;
                          lang?: string;
                          q: string;
                          size?: number;
                          taxonomy_names: string;
                      };
                  };
              },
              `${string}/${string}`,
          >,
      >

    • Parameters

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

          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?: null | 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: {
                      path: { identifier: string };
                      query: undefined | { index_id?: null | string };
                  };
              },
              `${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?: null | string;
            langs?: string;
            page?: number;
            page_size?: number;
            q?: null | string;
            sort_by?: null | string;
        }
        • Optionaldisplay_debug?: boolean
        • Optionalindex_id?: null | string

          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?: null | string
        • Optionalsort_by?: null | string

      Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: undefined;
                      header?: undefined;
                      path?: undefined;
                      query?: {
                          display_debug?: boolean;
                          index_id?: null
                          | string;
                          langs?: string;
                          page?: number;
                          page_size?: number;
                          q?: null | string;
                          sort_by?: null | string;
                      };
                  };
                  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: | undefined
                      | {
                          display_debug?: boolean;
                          index_id?: null
                          | string;
                          langs?: string;
                          page?: number;
                          page_size?: number;
                          q?: null | string;
                          sort_by?: null | string;
                      };
                  };
              },
              `${string}/${string}`,
          >,
      >

    • Parameters

      • body: {
            charts?:
                | null
                | (
                    | { chart_type: "DistributionChartType"; field: string }
                    | { chart_type: "ScatterChartType"; x: string; y: string }
                )[];
            facets?: null | string[];
            fields?: null | string[];
            index_id?: null | string;
            langs: string[];
            page: number;
            page_size: number;
            q?: null | string;
            sort_by?: null | string;
            sort_params?: null | Record<string, never>;
        }
        • Optionalcharts?:
              | null
              | (
                  | { chart_type: "DistributionChartType"; field: string }
                  | { chart_type: "ScatterChartType"; x: string; y: string }
              )[]

          Charts

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

        • Optionalfacets?: null | string[]

          Facets

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

        • Optionalfields?: null | string[]

          Fields

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

        • Optionalindex_id?: null | string

          Index Id

          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.

        • langs: string[]

          Langs

          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.
          
          [
          "en"
          ]
        • page: number

          Page

          Page to request, starts at 1.

          1
          
        • page_size: number

          Page Size

          Number of results to return per page.

          10
          
        • Optionalq?: null | string

          Q

          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?: null | string

          Sort By

          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
          
        • Optionalsort_params?: null | Record<string, never>

          Sort Params

          Additional parameters when using a sort script in sort_by. If the sort script needs parameters, you can only be used the POST method.

      Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: undefined;
                      header?: undefined;
                      path?: undefined;
                      query?: undefined;
                  };
                  requestBody: {
                      content: {
                          "application/json": {
                              charts?: | null
                              | (
                                  | { chart_type: "DistributionChartType"; field: string }
                                  | { chart_type: "ScatterChartType"; x: string; y: string }
                              )[];
                              facets?: null | string[];
                              fields?: null | string[];
                              index_id?: null | string;
                              langs: string[];
                              page: number;
                              page_size: number;
                              q?: null | string;
                              sort_by?: null | string;
                              sort_params?: null | Record<string, never>;
                          };
                      };
                  };
                  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?: | null
                      | (
                          | { chart_type: "DistributionChartType"; field: string }
                          | { chart_type: "ScatterChartType"; x: string; y: string }
                      )[];
                      facets?: null | string[];
                      fields?: null | string[];
                      index_id?: null | string;
                      langs: string[];
                      page: number;
                      page_size: number;
                      q?: null | string;
                      sort_by?: null | string;
                      sort_params?: null | Record<string, never>;
                  };
              },
              `${string}/${string}`,
          >,
      >

    • Parameters

      • query:
            | undefined
            | {
                charts?: string;
                facets?: string;
                fields?: string;
                index_id?: null
                | string;
                langs?: string;
                page?: number;
                page_size?: number;
                q?: null | string;
                sort_by?: null | string;
            }
        • undefined
        • {
              charts?: string;
              facets?: string;
              fields?: string;
              index_id?: null | string;
              langs?: string;
              page?: number;
              page_size?: number;
              q?: null | string;
              sort_by?: null | string;
          }
          • 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?: null | string

            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?: null | string

            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?: null | string

            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
            

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