collation – Tools for working with collations.

Tools for working with collations.

  • class pymongo.collation.Collation(locale, caseLevel=None, caseFirst=None, strength=None, numericOrdering=None, alternate=None, maxVariable=None, normalization=None, backwards=None, **kwargs)

Parameters:

  • locale: (string) The locale of the collation. This should be a stringthat identifies an ICU locale ID exactly. For example, en_US isvalid, but en_us and en-US are not. Consult the MongoDBdocumentation for a list of supported locales.

  • caseLevel: (optional) If True, turn on case sensitivity ifstrength is 1 or 2 (case sensitivity is implied if strength isgreater than 2). Defaults to False.

  • caseFirst: (optional) Specify that either uppercase or lowercasecharacters take precedence. Must be one of the following values:

  • strength: (optional) Specify the comparison strength. This is alsoknown as the ICU comparison level. This must be one of the followingvalues:

Each successive level builds upon the previous. For example, astrength of SECONDARY differentiatescharacters based both on the unadorned base character and its accents.

  • numericOrdering: (optional) If True, order numbers numericallyinstead of in collation order (defaults to False).

  • alternate: (optional) Specify whether spaces and punctuation areconsidered base characters. This must be one of the following values:

  • maxVariable: (optional) When alternate isSHIFTED, this option specifies whatcharacters may be ignored. This must be one of the following values:
  • normalization: (optional) If True, normalizes text into UnicodeNFD. Defaults to False.

  • backwards: (optional) If True, accents on characters areconsidered from the back of the word to the front, as it is done in someFrench dictionary ordering traditions. Defaults to False.

  • kwargs: (optional) Keyword arguments supplying any additional optionsto be sent with this Collation object.

  • class pymongo.collation.CollationStrength
  • An enum that defines values for strength on aCollation.

    • PRIMARY = 1
    • Differentiate base (unadorned) characters.

    • SECONDARY = 2

    • Differentiate character accents.

    • TERTIARY = 3

    • Differentiate character case.

    • QUATERNARY = 4

    • Differentiate words with and without punctuation.

    • IDENTICAL = 5

    • Differentiate unicode code point (characters are exactly identical).
  • class pymongo.collation.CollationAlternate
  • An enum that defines values for alternate on aCollation.

    • NONIGNORABLE = 'non-ignorable'_
    • Spaces and punctuation are treated as base characters.

    • SHIFTED = 'shifted'

    • Spaces and punctuation are not considered base characters.

Spaces and punctuation are distinguished regardless when theCollation strength is at leastQUATERNARY.

  • class pymongo.collation.CollationCaseFirst
  • An enum that defines values for case_first on aCollation.

    • UPPER = 'upper'
    • Sort uppercase characters first.

    • LOWER = 'lower'

    • Sort lowercase characters first.

    • OFF = 'off'

    • Default for locale or collation strength.
  • class pymongo.collation.CollationMaxVariable
  • An enum that defines values for max_variable on aCollation.

    • PUNCT = 'punct'
    • Both punctuation and spaces are ignored.

    • SPACE = 'space'

    • Spaces alone are ignored.