Types

Main types

class app._types.AggregateSearchParameters(*, facets: list[str] | None = None, charts: list[DistributionChart | ScatterChart] | None = None, charts_y_axis: bool = False)[source]
check_charts_are_valid()[source]

Check that the graph names are valid.

check_facets_are_valid()[source]

Check that the facets names are valid.

model_config = {}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

app._types.ChartsInfos[source]

Information about charts for a search result

alias of dict[str, dict[str, Any]]

class app._types.CommonParametersQuery[source]

Documentation and constraints for some common query parameters

class app._types.DebugInfo(*values)[source]

Debug information to return in the API

class app._types.DistributionChart(*, chart_type: Literal['DistributionChart'] = 'DistributionChart', field: str)[source]

Describes an entry for a distribution chart

model_config = {}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class app._types.ErrorSearchResponse(*, debug: SearchResponseDebug, errors: list[SearchResponseError])[source]
model_config = {}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class app._types.FacetInfo(*, name: str, items: list[FacetItem], count_error_margin: int | None = None)[source]

Search result for a facet

items: list[FacetItem][source]

Items in the facets

model_config = {}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str[source]

The display name of the facet

class app._types.FacetItem(*, key: str, name: str, count: int | None, selected: bool)[source]

Describes an entry of a facet

count: int | None[source]

The number of elements for this value

model_config = {}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

selected: bool[source]

Whether this value is selected

app._types.FacetsFilters[source]

Data about selected filters for each facet: facet name -> list of values

alias of dict[str, list[str]]

app._types.FacetsInfos[source]

Information about facets for a search result

alias of dict[str, FacetInfo]

class app._types.FetcherResult(*, status: FetcherStatus, document: dict[str, Any] | None)[source]

Result for a document fetcher

This is also used by pre-processors who have the opportunity to discard an entry

model_config = {}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class app._types.FetcherStatus(*values)[source]

Status of a fetcher

  • FOUND - document was found, index it

  • REMOVED - document was removed, remove it

  • SKIP - skip this document / update

  • RETRY - retry this document / update later

  • OTHER - unknown error

class app._types.GetSearchParameters(*, facets: list[str] | None = None, charts: list[DistributionChart | ScatterChart] | None = None, charts_y_axis: bool = False, fields: list[str] | None = None, page_size: Annotated[int, Ge(ge=1)] = 10, page: Annotated[int, Ge(ge=1)] = 1, sort_by: str | None = None, q: str | None = None, boost_phrase: bool = False, langs: list[str] = ['en'], index_id: str | None = None, debug_info: list[DebugInfo] | None = None)[source]

GET parameters for search

model_config = {'extra': 'forbid'}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

classmethod parse_charts_str(charts: str | list[str] | list[DistributionChart | ScatterChart] | None) → list[DistributionChart | ScatterChart] | None[source]

Parse for get params are ‘field’ or ‘xfield:yfield’ separated by ‘,’ for Distribution and Scatter charts.

Directly the dictionnaries in POST request

classmethod parse_value_str(value: str | list[str] | None) → list[str] | None[source]

Parse for get params ‘langs’

validate_q_or_sort_by()[source]

We want at least one of q or sort_by before launching a request

app._types.JSONType[source]

A precise expectation of what mappings looks like in json. (dict where keys are always of type str).

alias of dict[str, Any]

class app._types.PostSearchParameters(*, facets: list[str] | None = None, charts: list[DistributionChart | ScatterChart] | None = None, charts_y_axis: bool = False, fields: list[str] | None = None, page_size: Annotated[int, Ge(ge=1)] = 10, page: Annotated[int, Ge(ge=1)] = 1, sort_by: str | None = None, q: str | None = None, boost_phrase: bool = False, langs: list[str] = ['en'], index_id: str | None = None, debug_info: list[DebugInfo] | None = None, sort_params: dict[str, Any] | None = None)[source]

POST parameters for search

model_config = {'extra': 'forbid'}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

sort_by_scripts_needs_params()[source]

If sort_by is a script, verify we got corresponding parameters in sort_params

class app._types.QuerySearchParameters(*, q: str | None = None, boost_phrase: bool = False, langs: list[str] = ['en'], index_id: str | None = None)[source]

Parameters for search, this class concentrates on parameters that define the search query

check_max_results()[source]

Check we don’t ask too many results at once

property index_config[source]

Get the index config once and for all

property main_lang[source]

Get the main lang of the query

model_config = {}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

classmethod parse_langs_str(langs: str | list[str]) → list[str][source]

Parse for get params ‘langs’

property valid_index_id: str[source]

Give a not None index_id

This is mainly to avoid typing errors

validate_index_id()[source]

Validate index_id is known, or use default index if not provided

We call this validator as a model validator, because we want to be able to substitute the default None value, by the default index

class app._types.ResultSearchParameters(*, fields: list[str] | None = None, page_size: Annotated[int, Ge(ge=1)] = 10, page: Annotated[int, Ge(ge=1)] = 1, sort_by: str | None = None)[source]

Parameters that influence results presentation: pagination and sorting

model_config = {}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

sort_by_is_field_or_script()[source]

Verify sort_by is a valid field or script name

property uses_sort_script[source]

Does sort_by use a script?

class app._types.ScatterChart(*, chart_type: Literal['ScatterChart'] = 'ScatterChart', x: str, y: str)[source]

Describes an entry for a scatter plot

model_config = {}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class app._types.SearchParameters(*, facets: list[str] | None = None, charts: list[DistributionChart | ScatterChart] | None = None, charts_y_axis: bool = False, fields: list[str] | None = None, page_size: Annotated[int, Ge(ge=1)] = 10, page: Annotated[int, Ge(ge=1)] = 1, sort_by: str | None = None, q: str | None = None, boost_phrase: bool = False, langs: list[str] = ['en'], index_id: str | None = None, debug_info: list[DebugInfo] | None = None)[source]

Parameters for search, common to GET and POST

classmethod debug_info_list_from_str(debug_info: str | list[str] | list[DebugInfo] | None) → list[DebugInfo] | None[source]

We can pass a comma separated list of DebugInfo values as a string

model_config = {'extra': 'forbid'}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class app._types.SearchResponseDebug(*, lucene_query: str | None = None, es_query: dict[str, Any] | None = None, aggregations: dict[str, Any] | None = None)[source]
model_config = {}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class app._types.SearchResponseError(*, title: str, description: str | None = None, status: int | None = None)[source]
model_config = {}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class app._types.SuccessSearchResponse(*, hits: list[dict[str, Any]], aggregations: dict[str, Any] | None = None, facets: dict[str, FacetInfo] | None = None, charts: dict[str, dict[str, Any]] | None = None, page: int, page_size: int, page_count: int, debug: SearchResponseDebug | None = None, took: int, timed_out: bool, count: int, is_count_exact: bool, warnings: list[SearchResponseError] | None = None)[source]
model_config = {}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

pydantic model app._types.QueryAnalysis[source]

An object containing different information about the query.

Config:
  • arbitrary_types_allowed: bool = True

Fields:
field es_query: Query | None = None[source]

The query as an elasticsearch_dsl object

field facets_filters: dict[str, list[str]] | None = None[source]

The filters corresponding to the facets: a facet name and a list of values

field luqum_tree: Item | None = None[source]

The luqum tree corresponding to the text query

field text_query: str | None = None[source]

The initial text query

class app._types.QueryAnalysis(*, text_query: str | None = None, luqum_tree: Item | None = None, es_query: Query | None = None, facets_filters: dict[str, list[str]] | None = None)[source]

An object containing different information about the query.

es_query: Query | None[source]

The query as an elasticsearch_dsl object

facets_filters: dict[str, list[str]] | None[source]

The filters corresponding to the facets: a facet name and a list of values

luqum_tree: Item | None[source]

The luqum tree corresponding to the text query

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}[source]

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

text_query: str | None[source]

The initial text query

Validations

app.validations.check_all_values_are_fields_agg(index_id: str | None, values: list[str] | None) → list[str][source]

Check that all values are fields with aggregate: true property, that is, correspond to a field with aggregation. Used to check that charts are facets are valid.

app.validations.check_fields_are_numeric(index_id: str | None, values: list[str] | None) → list[str][source]
  • If field exists in global_config, check that it’s numeric.

  • If field looks like x.y and x.y does not exist in global config, check that x is an object field

app.validations.check_index_id_is_defined(index_id: str | None, config: Config) → None[source]

Check that the index ID is defined in the configuration.

Raise an HTTPException if it’s not the case.

Parameters:
  • index_id – index ID to check

  • config – configuration to check against