Analytics Mapping Functions

Mapping functions map values for each Solr Document or Reduction.

Below is a list of all mapping functions provided by the Analytics Component. These mappings can be chained together to implement more complex functionality.

Numeric Functions

Negation

Negates the result of a numeric expression.

neg(<_Numeric_ T>) => <T>
  • neg(10.53) => -10.53

  • neg([1, -4]) => [-1, 4]

Absolute Value

Returns the absolute value of the numeric expression.

abs(< Numeric T >) => < T >
  • abs(-10.53) => 10.53

  • abs([1, -4]) => [1, 4]

Round

Rounds the numeric expression to the nearest Integer or Long value.

round(< Float >) => < Int >
round(< Double >) => < Long >
  • round(-1.5) => -1

  • round([1.75, 100.34]) => [2, 100]

Ceiling

Rounds the numeric expression to the nearest Integer or Long value that is greater than or equal to the original value.

ceil(< Float >) => < Int >
ceil(< Double >) => < Long >
  • ceil(5.01) => 5

  • ceil([-4.999, 6.99]) => [-4, 7]

Floor

Rounds the numeric expression to the nearest Integer or Long value that is less than or equal to the original value.

floor(< Float >) => < Int >
floor(< Double >) => < Long >
  • floor(5.75) => 5

  • floor([-4.001, 6.01]) => [-5, 6]

Addition

Adds the values of the numeric expressions.

add(< Multi Double >) => < Single Double >
  • add([1, -4]) => -3.0

add(< Single Double >, < Multi Double >) => < Multi Double >
  • add(3.5, [1, -4]) => [4.5, -0.5]

add(< Multi Double >, < Single Double >) => < Multi Double >
  • add([1, -4], 3.5) => [4.5, -0.5]

add(< Single Double >, …​) => < Single Double >
  • add(3.5, 100, -27.6) => 75.9

Subtraction

Subtracts the values of the numeric expressions.

sub(< Single Double >, < Single Double >) => < Single Double >
  • sub(3.5, 100) => -76.5

sub(< Single Double >, < Multi Double >) => < Multi Double >
  • sub(3.5, [1, -4]) => [2.5, 7.5]

sub(< Multi Double >, < Single Double >) => < Multi Double >
  • sub([1, -4], 3.5) => [-2.5, -7.5]

Multiplication

Multiplies the values of the numeric expressions.

mult(< Multi Double >) => < Single Double >
  • mult([1, -4]) => -4.0

mult(< Single Double >, < Multi Double >) => < Multi Double >
  • mult(3.5, [1, -4]) => [3.5, -16.0]

mult(< Multi Double >, < Single Double >) => < Multi Double >
  • mult([1, -4], 3.5) => [3.5, 16.0]

mult(< Single Double >, …​) => < Single Double >
  • mult(3.5, 100, -27.6) => -9660

Division

Divides the values of the numeric expressions.

div(< Single Double >, < Single Double >) => < Single Double >
  • div(3.5, 100) => .035

div(< Single Double >, < Multi Double >) => < Multi Double >
  • div(3.5, [1, -4]) => [3.5, -0.875]

div(< Multi Double >, < Single Double >) => < Multi Double >
  • div([1, -4], 25) => [0.04, -0.16]

Power

Takes one numeric expression to the power of another.

NOTE: The square root function sqrt(< Double >) can be used as shorthand for pow(< Double >, .5)

pow(< Single Double >, < Single Double >) => < Single Double >
  • pow(2, 4) => 16.0

pow(< Single Double >, < Multi Double >) => < Multi Double >
  • pow(16, [-1, 0]) => [0.0625, 1]

pow(< Multi Double >, < Single Double >) => < Multi Double >
  • pow([1, 16], .25) => [1.0, 2.0]

Logarithm

Takes one logarithm of numeric expressions, with an optional second numeric expression as the base. If only one expression is given, the natural log is used.

log(< Double >) => < Double >
  • log(5) => 1.6094…​

  • log([1.0, 100.34]) => [0.0, 4.6085…​]

log(< Single Double >, < Single Double >) => < Single Double >
  • log(2, 4) => 0.5

log(< Single Double >, < Multi Double >) => < Multi Double >
  • log(16, [2, 4]) => [4, 2]

log(< Multi Double >, < Single Double >) => < Multi Double >
  • log([81, 3], 9) => [2.0, 0.5]

Logic

Negation

Negates the result of a boolean expression.

neg(< Bool >) => < Bool>
  • neg(F) => T

  • neg([F, T]) => [T, F]

And

ANDs the values of the boolean expressions.

and(< Multi Bool >) => < Single Bool >
  • and([T, F, T]) => F

and(< Single Bool >, < Multi Bool >) => < Multi Bool >
  • and(F, [T, T]) => [F, F]

and(< Multi Bool >, < Single Bool >) => < Multi Bool >
  • and([F, T], T) => [F, T]

and(< Single Bool >, …​) => < Single Bool >
  • and(T, T, T) => T

Or

ORs the values of the boolean expressions.

or(< Multi Bool >) => < Single Bool >
  • or([T, F, T]) => T

or(< Single Bool >, < Multi Bool >) => < Multi Bool >
  • or(F, [F, T]) => [F, T]

or(< Multi Bool >, < Single Bool >) => < Multi Bool >
  • or([F, T], T) => [T, T]

or(< Single Bool >, …​) => < Single Bool >
  • or(F, F, F) => F

Exists

Checks whether any value(s) exist for the expression.

exists( T ) => < Single Bool >
  • exists([1, 2, 3]) => T

  • exists([]) => F

  • exists(empty) => F

  • exists('abc') => T

Comparison

Equality

Checks whether two expressions' values are equal. The parameters must be the same type, after implicit casting.

equal(< Single T >, < Single T >) => < Single Bool >
  • equal(F, F) => T

equal(< Single T >, < Multi T >) => < Multi Bool >
  • equal("a", ["a", "ab"]) => [T, F]

equal(< Multi T >, < Single T >) => < Multi Bool >
  • equal([1.5, -3.0], -3) => [F, T]

Greater Than

Checks whether a numeric or Date expression’s values are greater than another expression’s values. The parameters must be the same type, after implicit casting.

gt(< Single Numeric/Date T >, < Single T >) => < Single Bool >
  • gt(1800-01-02, 1799-12-20) => F

gt(< Single Numeric/Date T >, < Multi T >) => < Multi Bool >
  • gt(30.756, [30, 100]) => [F, T]

gt(< Multi Numeric/Date T >, < Single T >) => < Multi Bool >
  • gt([30, 75.6], 30) => [F, T]

Greater Than or Equals

Checks whether a numeric or Date expression’s values are greater than or equal to another expression’s values. The parameters must be the same type, after implicit casting.

gte(< Single Numeric/Date T >, < Single T >) => < Single Bool >
  • gte(1800-01-02, 1799-12-20) => F

gte(< Single Numeric/Date T >, < Multi T >) => < Multi Bool >
  • gte(30.756, [30, 100]) => [F, T]

gte(< Multi Numeric/Date T >, < Single T >) => < Multi Bool >
  • gte([30, 75.6], 30) => [T, T]

Less Than

Checks whether a numeric or Date expression’s values are less than another expression’s values. The parameters must be the same type, after implicit casting.

lt(< Single Numeric/Date T >, < Single T >) => < Single Bool >
  • lt(1800-01-02, 1799-12-20) => T

lt(< Single Numeric/Date T >, < Multi T >) => < Multi Bool >
  • lt(30.756, [30, 100]) => [T, F]

lt(< Multi Numeric/Date T >, < Single T >) => < Multi Bool >
  • lt([30, 75.6], 30) => [F, F]

Less Than or Equals

Checks whether a numeric or Date expression’s values are less than or equal to another expression’s values. The parameters must be the same type, after implicit casting.

lte(< Single Numeric/Date T >, < Single T >) => < Single Bool >
  • lte(1800-01-02, 1799-12-20) => T

lte(< Single Numeric/Date T >, < Multi T >) => < Multi Bool >
  • lte(30.756, [30, 100]) => [T, F]

lte(< Multi Numeric/Date T >, < Single T >) => < Multi Bool >
  • lte([30, 75.6], 30) => [T, F]

Top

Returns the maximum of the numeric, Date or String expression(s)' values. The parameters must be the same type, after implicit casting. (Currently the only type not compatible is Boolean, which will be converted to a String implicitly in order to compile the expression)

top(< Multi T >) => < Single T >
  • top([30, 400, -10, 0]) => 400

top(< Single T >, …​) => < Single T >
  • top("a", 1, "d") => "d"

Bottom

Returns the minimum of the numeric, Date or String expression(s)' values. The parameters must be the same type, after implicit casting. (Currently the only type not compatible is Boolean, which will be converted to a String implicitly in order to compile the expression)

bottom(< Multi T >) => < Single T >
  • bottom([30, 400, -10, 0]) => -10

bottom(< Single T >, …​) => < Single T >
  • bottom("a", 1, "d") => "1"

Conditional

If

Returns the value(s) of the THEN or ELSE expressions depending on whether the boolean conditional expression’s value is true or false. The THEN and ELSE expressions must be of the same type and cardinality after implicit casting is done.

if(< Single Bool>, < T >, < T >) => < T >
  • if(true, "abc", [1,2]) => ["abc"]

  • if(false, "abc", 123) => "123"

Replace

Replace all values from the 1st expression that are equal to the value of the 2nd expression with the value of the 3rd expression. All parameters must be the same type after implicit casting is done.

replace(< T >, < Single T >, < Single T >) => < T >
  • replace([1,3], 3, "4") => ["1", "4"]

  • replace("abc", "abc", 18) => "18"

  • replace("abc", 1, "def") => "abc"

Fill Missing

If the 1st expression does not have values, fill it with the values for the 2nd expression. Both expressions must be of the same type and cardinality after implicit casting is done

fill_missing(< T >, < T >) => < T >
  • fill_missing([], 3) => [3]

  • fill_missing(empty, "abc") => "abc"

  • fill_missing("abc", [1]) => ["abc"]

Remove

Remove all occurrences of the 2nd expression’s value from the values of the 1st expression. Both expressions must be of the same type after implicit casting is done

remove(< T >, < Single T >) => < T >
  • remove([1,2,3,2], 2) => [1, 3]

  • remove("1", 1) => empty

  • remove(1, "abc") => "1"

Filter

Return the values of the 1st expression if the value of the 2nd expression is true, otherwise return no values.

filter(< T >, < Single Boolean >) => < T >
  • filter([1,2,3], true) => [1,2,3]

  • filter([1,2,3], false) => []

  • filter("abc", false) => empty

  • filter("abc", true) => 1

Date

Date Parse

Explicitly converts the values of a String or Long expression into Dates.

date(< String >) => < Date >
  • date('1800-01-02') => 1800-01-02T​00:00:00Z

  • date(['1800-01-02', '2016-05-23']) => [1800-01-02T…​, 2016-05-23T…​]

date(< Long >) => < Date >
  • date(1232343246648) => 2009-01-19T​05:34:06Z

  • date([1232343246648, 223234324664]) => [2009-01-19T…​, 1977-01-27T…​]

Date Math

Compute the given date math strings for the values of a Date expression. The date math strings must be constant.

date_math(< Date >, < Constant String >…​) => < Date >
  • date_math(1800-04-15, '+1DAY', '-1MONTH') => 1800-03-16

  • date_math([1800-04-15,2016-05-24], '+1DAY', '-1MONTH') => [1800-03-16, 2016-04-25]

String

Explicit Casting

Explicitly casts the expression to a String expression.

string(< String >) => < String >
  • string(1) => '1'

  • string([1.5, -2.0]) => ['1.5', '-2.0']

Concatenation

Concatenations the values of the String expression(s) together.

concat(< Multi String >) => < Single String >
  • concat(['a','b','c']) => 'abc'

concat(< Single String >, < Multi String >) => < Multi String >
  • concat(1, ['a','b','c']) => ['1a','1b','1c']

concat(< Multi String >, < Single String >) => < Multi String >
  • concat(['a','b','c'], 1) => ['a1','b1','c1']

concat(< Single String >…​) => < Single String >
  • concat('a','b','c') => 'abc'

  • concat('a',empty,'c') => 'ac'
    Empty values are ignored

Separated Concatenation

Concatenations the values of the String expression(s) together using the given constant string value as a separator.

concat_sep(< Constant String >, < Multi String >) => < Single String >
  • concat_sep('-', ['a','b']) => 'a-b'

concat_sep(< Constant String >, < Single String >, < Multi String >) => < Multi String >
  • concat_sep(2,1,['a','b']) => ['12a','12b']

concat_sep(< Constant String >, < Multi String >, < Single String >) => < Multi String >
  • concat_sep(2,['a','b'],1) => ['a21','b21']

  • concat_sep('-','a',2,3) => 'a-2-3'

  • concat_sep(';','a',empty,'c') => 'a;c'
    Empty values are ignored