Class ConfigurableShareLimiter
- java.lang.Object
-
- de.cxp.ocs.smartsuggest.limiter.ConfigurableShareLimiter
-
- All Implemented Interfaces:
Limiter
public class ConfigurableShareLimiter extends Object implements Limiter
Limiter where you can configure, which group of suggestions should get which share in the result (e.g. keywords=0.5 (50%), brand=0.3 (30%), category=0.2 (20%)).
That configuration can be done by the Map given in the constructor or by defining system property or environment variables with the group values prefixed by "SUGGEST_GROUP_SHARE_" keyword, e.g. the group "brand" could be configured with environment variable "SUGGEST_GROUP_SHARE_BRAND=0.2". (It's also possible to combine these configuration possibilities, but why would you do that..).
The configured values should sum up to 1.0. If that's not the case, they are normalized accordingly.
The order of the returned groups is defined by the order in the configuration. This is why it must be a LinkedHashMap. Groups that are not configured or configured by environment variables, will be appended to that configuration according to their appearance in the results.
If one or more group are not configured at all, they either get the same weight as the lowest configured group, or - in case the configured shares sum up to a value lower 1, the remaining share will evenly be distributed over the not-configured groups.
To group the results properly, a "groupKey" has to be specified. It is then looked up at the pay-load of the suggestions. If a suggestion has no value for that key, "other" is used. This means you should also consider configuring the value of the "other" group.
If a result can't be distributed evenly, the remaining space will be filled up with suggestions according to the group priority order - or the value of the least important group will be truncated.
-
-
Field Summary
Fields Modifier and Type Field Description static StringOTHER_SHARE_KEYstatic StringSHARE_KEY_ENV_PREFIX
-
Constructor Summary
Constructors Constructor Description ConfigurableShareLimiter(String groupingKey, LinkedHashMap<String,Double> shareConfiguration, Optional<String[]> groupDeduplicationOrder)The share limiter will group the results according to a particular payload value and uses the configured share values to distribute the limited space among those grouped suggestions.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<Suggestion>limit(List<Suggestion> suggestions, int limit)
-
-
-
Field Detail
-
SHARE_KEY_ENV_PREFIX
public static final String SHARE_KEY_ENV_PREFIX
- See Also:
- Constant Field Values
-
OTHER_SHARE_KEY
public static final String OTHER_SHARE_KEY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ConfigurableShareLimiter
public ConfigurableShareLimiter(@Nonnull String groupingKey, LinkedHashMap<String,Double> shareConfiguration, Optional<String[]> groupDeduplicationOrder)
The share limiter will group the results according to a particular payload value and uses the configured share values to distribute the limited space among those grouped suggestions.- Parameters:
groupingKey- which key to use to get the grouping key from the suggestions payload.shareConfiguration- the share value (between 0 and 1) for each available group. The order of the groups matters. See java-doc of ConfigurableShareLimitergroupDeduplicationOrder- If given (even with an empty array), the suggestions will be deduplicated. The array defines preferred groups. Suggestions of the groups defined first will be preferred over suggestions from other groups.- See Also:
ConfigurableShareLimiter
-
-
Method Detail
-
limit
public List<Suggestion> limit(List<Suggestion> suggestions, int limit)
-
-