Schema

This package contains core entities that are used in the search index and various tools for working with them.

sir.schema.SCHEMA = {'annotation': <sir.schema.searchentities.SearchEntity object>, 'area': <sir.schema.searchentities.SearchEntity object>, 'artist': <sir.schema.searchentities.SearchEntity object>, 'cdstub': <sir.schema.searchentities.SearchEntity object>, 'editor': <sir.schema.searchentities.SearchEntity object>, 'event': <sir.schema.searchentities.SearchEntity object>, 'instrument': <sir.schema.searchentities.SearchEntity object>, 'label': <sir.schema.searchentities.SearchEntity object>, 'place': <sir.schema.searchentities.SearchEntity object>, 'recording': <sir.schema.searchentities.SearchEntity object>, 'release': <sir.schema.searchentities.SearchEntity object>, 'release-group': <sir.schema.searchentities.SearchEntity object>, 'series': <sir.schema.searchentities.SearchEntity object>, 'tag': <sir.schema.searchentities.SearchEntity object>, 'url': <sir.schema.searchentities.SearchEntity object>, 'work': <sir.schema.searchentities.SearchEntity object>}

Maps core names to SearchEntity objects.

sir.schema.generate_update_map()[source]

Generates mapping from tables to Solr cores (entities) that depend on these tables and the columns of those tables. In addition provides a path along which data of an entity can be retrieved by performing a set of JOINs and a map of table names to SQLAlchemy ORM models and other useful mappings.

Uses paths to determine the dependency.

:rtype (dict, dict, dict, dict)

class sir.schema.searchentities.SearchEntity(model, fields, version, compatconverter=None, extrapaths=None, extraquery=None)[source]

Bases: object

An entity with searchable fields.

Parameters:
  • model – A declarative class.
  • fields (list) – A list of SearchField objects.
  • version (float) – The supported schema version of this entity.
  • compatconverter – A function to convert this object into an XML document compliant with the MMD schema version 2
  • extrapaths ([str]) – A list of paths that don’t correspond to any field but are used by the compatibility conversion
  • extraquery – A function to apply to the object returned by query().
build_entity_query()[source]

Builds a sqlalchemy.orm.query.Query object for this entity (an instance of sir.schema.searchentities.SearchEntity) that eagerly loads the values of all search fields.

Return type:sqlalchemy.orm.query.Query
query

See build_entity_query().

query_result_to_dict(obj)[source]

Converts the result of single query result into a dictionary via the field specification of this entity.

Parameters:obj – A declarative object.
Return type:dict
class sir.schema.searchentities.SearchField(name, paths, transformfunc=None, trigger=True)[source]

Bases: object

Represents a searchable field.

Each search field has a name and a set of paths. Name is used to reference a field in search queries. Path indicates where the value of that field can be found.

Paths are structured in the following way:

[<one or multiple dot-delimited relationships>.]<column name>

These paths can then be mapped to actual relationships and columns defined in the MusicBrainz schema (see sir.schema package and mbdata module).

For example, path “areas.area.gid”, when bound to the CustomAnnotation model would be expanded in the following way:

  1. areas relationship from the CustomAnnotation class
  2. area relationship from the AreaAnnotation class (model)
  3. gid column from the Area class (model)
Parameters:
  • name (str) – The name of the field.
  • paths ([str]) – A dot-delimited path (or a list of them) along which the value of this field can be found, beginning at an instance of the model class this field is bound to. See class documentation for more details.
  • transformfunc (method) – An optional function to transform the value before sending it to Solr.
sir.schema.searchentities.defer_everything_but(mapper, load, *columns)[source]
sir.schema.searchentities.is_composite_column(model, colname)[source]

Checks if a models attribute is a composite column.

Parameters:
Return type:

bool

sir.schema.searchentities.merge_paths(field_paths)[source]

Given a list of paths as field_paths, return a dict that, for each level of the path, includes a dictionary whose keys are the columns to load and the values are other dictionaries of the described structure.

Parameters:field_paths ([[str]]) –
Return type:dict