CmpStr - v3.2.1
    Preparing search index...

    Class StructuredData<T, R>

    The StructuredData class provides factory methods for processing arrays of structured objects with string comparison capabilities.

    Type Parameters

    • T = any

      The type of objects in the data array

    • R = MetricRaw

      The type of the metric raw result

    Index

    Constructors

    • Creates a new StructuredData instance.

      Type Parameters

      • T = any

        The type of objects in the data array

      • R = MetricRaw

        The type of the metric raw result

      Parameters

      • data: T[]

        The array of objects to process

      • key: keyof T

        The property key to extract for comparison

      Returns StructuredData<T, R>

    Properties

    data: T[]

    The array of objects to process

    key: keyof T

    The property key to extract for comparison

    Methods

    • Extracts string values from the data array using the configured key.

      Returns string[]

      • Array of extracted strings
    • Extracts properties from another array.

      Type Parameters

      • A

        The type of objects in the array

      Parameters

      • arr: readonly A[]

        The array to extract from

      • key: keyof A

        The property key

      Returns string[]

      • Array of extracted strings
    • Normalizes metric results to a consistent format. Attaches original indices for correct mapping after sorting. Handles both CmpStrResult[] and MetricResultBatch formats.

      Parameters

      Returns IndexedResult<R>[]

      • Normalized results with indices
      • If results format is unsupported
    • Rebuilds results with original objects attached. Maps results to source objects using target string matching with duplicate handling. Works correctly even when results are filtered or subset (e.g., from closest/furthest).

      Parameters

      • results: IndexedResult<R>[]

        The normalized metric results

      • sourceData: T[]

        The source data array for object attachment

      • extractedStrings: string[]

        The extracted strings array for index mapping

      • OptionalremoveZero: boolean

        Whether to remove zero similarity results

      • OptionalobjectsOnly: boolean

        Return only objects without metadata

      Returns T[] | StructuredDataResult<T, R>[]

      • Results with objects (or just objects if objectsOnly=true)