Skip to content

FILTER

The FILTER function filters a set of domains by returning a new set which contains domains from the source set chosen based on their relative score.
The function creates a virtual sequence of the domains of the source set in descending score order. It always takes the first domain—that is the domain with the highest score—,and then the other domains in the sequence, one after the other, if their score is equal to or greater than a fraction of the score of the previous domain. The fraction of score 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);

populates mySet with the first domain of workingSet in the descending score sequence, the second domain if its score is greater than or equal to 50% of the score of the first and the third if its score is greater than or equal to 50% of the score of the second.
So the function returns 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 mySet returns:

1   Sport (score: 90)
1.01    martial art (score: 60)

because the highest scoring domain in workingSet has a score of 90, the fraction is 50, 50% of 90 is 45 and domain 1.01 has a score of 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 than 50% of the score of the previous domain. The previous domain has indeed a score of 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. The fractions in the array are applied, one after the other, to the comparison between the scores 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, using the first fraction to compare the score of the second domain with that of the first, then the second fraction to compare the score of the third domain with the score of the second.
So the function populates mySet with:

1   Sport (score: 90)
1.01    martial art (score: 60)
1.15    rugby (score: 10)

1.01 is included because its score is greater than 10% of the score of the first domain, while 1.15 is included because its score is greater than 9, which is 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 of set that the score of a domain must have to be included in the resulting set.

or:

FILTER(set, [score fractions])

where score fractions is a comma separated list of fractions. The number of fractions corresponds to the maximum number of domains to take from set in addition to the one with the highest score. Fractions are applied one after the other to pairs of domains—in the descending score sequence—when comparing their score: the first fraction is used to compare the score of the second domain with that of the first, the second fraction to compare the score of the third domain with that of the second, 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 leads to the random selection 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 its score is at least 15% of the score of the first domain.
Since domains 1.07 and 1.15 have the same score (10) and this score is greater than 9 (which is 15% of 60), both are candidates for inclusion in the result set, but only one is chosen, randomly, so mySet can be either:

1.01
1.07

or:

1.01
1.15

To have both domains, it's necessary to 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 integer.