FILTER
The FILTER
function returns a new set containing domains from an another set chosen based on their relative score, in particular the highest scoring domain plus any domain with a score equal or greater than a fraction of the score of the previous in the descending score sequence. The fraction is expressed in hundredths.
For example, if the hidden results table is the one in the introduction, this code:
var workingSet = SET(["1.15", "1", "1.01"]);
var mySet = FILTER(workingSet, 50);
puts in mySet
the first domain of workingSet
in the descending sort sequence, the second domain if its score is greater of equal than the 50% of the score of the first, the third if its score is greater of equal than the 50% of the score of the second and so on for the remaining domains until domains with sufficient score are found.
So the function sets workingSet
with these domains:
Domain ID | Domain label | Score |
---|---|---|
1.15 | rugby | 10 |
1 | Sport | 90 |
1.01 | martial art | 60 |
with the descending score sequence being:
1. 1 Sport (score: 90)
2. 1.01 martial art (score: 60)
3. 1.15 rugby (score: 10)
then sets mySet
to:
1 Sport (score: 90)
1.01 martial art (score: 60)
because the highest scoring domain in workingSet
has score 90, the fraction is 50, 50% of 90 is 45 and domain 1.01
has score 60 which is greater than 45.
The function evaluates also the next domain in the descending score sequence (1.15
), but ignores it and stops because its score (10) is less the 50% of the score of the previous domain. In fact the previous domain has score 60, 50% of 60 is 30 and 10 is lower than that.
It is possible to list more fractions with an array. In this case the maximum number of domains included in the result set will be one plus the number of items of the array and the fractions in the array are applied to the comparison between the score of subsequent couples of domains.
For example, in this code:
var workingSet = SET(["1.15", "1", "1.01"]);
var mySet = FILTER(workingSet, [10, 15]);
FILTER
returns at most three domains, uses the first fraction to compare the score of the second domain with that of the first and the second fraction to compare the score of the third domain with the score of the second.
So the function sets mySet
to:
1 Sport (score: 90)
1.01 martial art (score: 60)
1.5 rugby (score: 10)
because the score of 1.01
is more than 10% of the score of the first domain and the third domain is included too because its score is greater than 9, which is the 15% of the score of the second domain.
The syntax of the FILTER
function is:
FILTER(set, score fraction)
where:
set
is a set variable.score fraction
(integer) is the minimum number of hundredths of the score of the previous domain in the descending score sequence ofset
that the score of a domain must have to be included in the resulting set.
or:
FILTER(set, score fractions)
where score fractions
it is an array of fractions whose number corresponds to the maximum number of domains taken from set
in addition to the one with the highest score and whose sequence corresponds to the position of the pair of domains, in the descending score sequence, to which the fraction applies: first fraction for the first-second pair, second fraction for the second-third pair and so on.
Info
If two domains have the same score, they are nevertheless considered one before the other in the descending score sequence. This could lead to the random pick of one of the two in situations like the one exemplified below, which again refers to the hidden results table in the introduction.
var workingSet = SET(["1.01", "1.07", "1.15"]);
var mySet = FILTER(workingSet, [15]);
mySet
can include at most two domains: 1.01
, because it's the one with the highest score in workingSet
, and the second domain in the descending score sequence if it's score is at least 15% of the score of the first domain.
Since domains 1.07
and 1.15
both have the same score (10) and this score is more than 9, which if 15% of 60, both are candidates, but the one that is taken is chosen at random, so mySet
can be either:
1.01
1.07
or:
1.01
1.15
To have both domains, it's necessary to give up the constraint on the maximum number of results and either add the fraction 100 to the array, which causes the addition of the third domain because it has the same score of the second or use the syntax with only one fraction.