# Functions
1search contains four predefined function types that you can configure with index parameters of their choice. The four types of 1search functions are:
- Aggregate functions
- Join functions
- Tuple functions
- Count functions
Any function you wish to add to your 1search implementation must be specified within a <Functions> tag. Descriptions of each function type are provided below.
# Aggregate Function
# Description
An aggregate function takes multiple indexes as parameters and combines them to return a single summary value.
Index values to be taken as parameters for an aggregate function must be specified as <Value> child tags within the <Aggregate> tag.
# Syntax
<Functions>
<Aggregate Name="string">
<Value Key="string"/>
<Value Key="string"/>
</Aggregate>
</Functions>
# Attributes
Note: attributes marked with * are required.
Within the <Aggregate> tag:
- Name* (string) :
- The name of the function that is used when invoked. This value must be unique across all other functions specified.
Within the <Value> tag:
- Key* (string) :
- Specifies a JSON Path to be used with the aspect name the function is working on (can be multiple keys).
# Join Function
# Description
A join function will take the string values of 2+ indexes as parameters, a return a single string of the conjoined values.
Index values to be taken as parameters for a join function must be specified as <Value> child tags within the <Join> tag.
# Syntax
<Functions>
<Join Name="string" Separator = "character" >
<Value Key="string"/>
<Value Key="string"/>
</Join>
</Functions>
# Attributes
Note: attributes marked with * are required.
Within the <Join> tag:
- Name* (string) :
- The name of the function that is used when invoked. This value must be unique across all other functions specified.
- Separator (character) (default: "") :
- The character that will be used in between the joined strings.
Within the <Value> tag:
- Key* (string) :
- This value must be equal to the key of the index that you are referring to.
# Example One
Let's say you had the aspects "Genre" and "Series" for a search engine of books. And you wanted to join these two facets into one string, separated by an underscore.
# Code
The following XML would be required,
<Functions>
<Join Name="GenreSeriesJoinFunction" Separator="_">
<Value Key="Specification.Genre"/>
<Value Key="Specification.Series"/>
</Join>
</Functions>
# Result
If you used the above function using the Genre facet "Manga" and the Series facet "DragonBall" as parameters, the following string would be produced:
"Manga_DragonBall"
# Tuple Function
# Description
A tuple function takes 2+ indexes as parameters and returns a single index data type composed of the indexes provided.
Index values to be taken as parameters for a tuple function must be specified as <Value> child tags within the <Tuple> tag.
# Syntax
<Functions>
<Tuple Name="string">
<Value Name="string" Key="string"/>
<Value Name="string" Key="string"/>
</Tuple>
</Functions>
# Attributes
Within the <Tuple> tag:
- Name* (string) :
- The name of the function that is used when invoked. This value must be unique across all other functions specified.
Within the <Value> tag:
- Name* (string) :
- The name is used to access the specific index value within the tuple. As such, the name must be unique across all other values specified within the tuple.
- Key* (string) :
- This value must be equal to the key of the index that you are referring to.
# Example One
Let's say you wanted to use a tuple function to return two values, "Longitude" and "Latitude" for a GPS coordinate.
# Code
The above function could be written using the following XML:
<Functions>
<Tuple Name="GpsCoordinateTuple">
<Value Name="Latitude" Key="GpsCoordinate.Latitude"/>
<Value Name="Longitude" Key="GpsCoordinate.Longitude"/>
</Tuple>
</Functions>
# Count Function
# Description
The count function returns the number of facets or values of the index given as a parameter.
# Syntax
<Functions>
<Count Name="string" Key="string"/>
</Functions>
# Attributes
Note: attributes marked with * are required.
- Name* (string) :
- The name of the function that is used when invoked. This value must be unique across all other functions specified.
- Key* (string) :
- This value must be equal to the key of the index whose values you wish to count.
