GroupBy

Splits a sequence of documents into groups based on a specified function or metadata key.
This module forms groups from the output documents of the specified modules. Each input document is cloned for each group and metadata related to the groups, including the sequence of documents for each group, is added to each clone. For example, if you have 2 input documents and the result of grouping is 3 groups, this module will output 6 documents.

Usage

  • GroupBy(DocumentConfig key, IEnumerable<IModule> modules)

    Partitions the result of the specified modules into groups with matching keys based on the key delegate. The input documents to GroupBy are used as the initial input documents to the specified modules.

    • key

      A delegate that returns the group key.

    • modules

      Modules to execute on the input documents prior to grouping.

  • GroupBy(DocumentConfig key, params IModule[] modules)

    Partitions the result of the specified modules into groups with matching keys based on the key delegate. The input documents to GroupBy are used as the initial input documents to the specified modules.

    • key

      A delegate that returns the group key.

    • modules

      Modules to execute on the input documents prior to grouping.

  • GroupBy(string keyMetadataKey, IEnumerable<IModule> modules)

    Partitions the result of the specified modules into groups with matching keys based on the value at the specified metadata key. If a document to group does not contain the specified metadata key, it is not included in any output groups. The input documents to GroupBy are used as the initial input documents to the specified modules.

    • keyMetadataKey

      The key metadata key.

    • modules

      Modules to execute on the input documents prior to grouping.

  • GroupBy(string keyMetadataKey, params IModule[] modules)

    Partitions the result of the specified modules into groups with matching keys based on the value at the specified metadata key. If a document to group does not contain the specified metadata key, it is not included in any output groups. The input documents to GroupBy are used as the initial input documents to the specified modules.

    • keyMetadataKey

      The key metadata key.

    • modules

      Modules to execute on the input documents prior to grouping.

Fluent Methods

Chain these methods together after the constructor to modify behavior.

  • Where(DocumentConfig predicate)

    Limits the documents to be grouped to those that satisfy the supplied predicate.

    • predicate

      A delegate that should return a bool.

  • WithComparer(IEqualityComparer<Object> comparer)

    Specifies an equality comparer to use for the grouping.

    • comparer

      The equality comparer to use.

  • WithComparer<TValue>(IEqualityComparer<TValue> comparer)

    Specifies a typed equality comparer to use for the grouping. A conversion to the comparer type will be attempted for all metadata values. If the conversion fails, the value will not be considered equal. Note that this will also have the effect of treating different convertible types as being of the same type. For example, if you have two group keys, 1 and "1" (in that order), and use a string-based comparison, you will only end up with a single group for those documents with a group key of 1 (since the int key came first).

    • comparer

      The typed equality comparer to use.

  • WithEmptyOutputIfNoGroups(bool emptyOutput = true)

    Specifies that no documents should be output if there are no groups. This is in contrast to the default behavior of outputting the unmodified input documents if no groups were found.

    • emptyOutput

      true to not output documents when no groups are found.

Output Metadata

The metadata values listed below apply to individual documents and are created and set by the module as indicated in their descriptions.

  • Keys.GroupDocuments: IEnumerable<IDocument>

    Contains all the documents for the current group.

  • Keys.GroupKey: System.Object

    The key for the current group.

GitHub