for (Map.Entry<Float, Collection<String>> invTypeEl: invTypeWeights.asMap().entrySet()) {
if (null == score.sourceWeights) { // Easy case
manualWeights.add(FilterBuilders.termsFilter(DocumentPojo.mediaType_, invTypeEl.getValue().toArray()), invTypeEl.getKey());
}
else { // Need to filter out sources they are matched with higher prio
BoolFilterBuilder typesNotSources = FilterBuilders.boolFilter();
typesNotSources = typesNotSources.must(FilterBuilders.termsFilter(DocumentPojo.mediaType_, invTypeEl.getValue().toArray())).
mustNot(FilterBuilders.termsFilter(DocumentPojo.sourceKey_, score.sourceWeights.keySet().toArray()));
manualWeights.add(typesNotSources, invTypeEl.getKey());
}
}
}//TESTED
if (null != score.tagWeights) {
// Find all weightings with the same score:
ArrayListMultimap<Float, String> invTagWeights = ArrayListMultimap.create();
for (Map.Entry<String, Double> tagEl: score.tagWeights.entrySet()) {
invTagWeights.put((float)(double)tagEl.getValue(), tagEl.getKey());
}
for (Map.Entry<Float, Collection<String>> invTagEl: invTagWeights.asMap().entrySet()) {
if ((null == score.sourceWeights) && (null == score.typeWeights)) { // Easy case
manualWeights.add(FilterBuilders.termsFilter(DocumentPojo.tags_, invTagEl.getValue().toArray()), invTagEl.getKey());
}
else { // need to exclude types or sources
BoolFilterBuilder typesNotSources = FilterBuilders.boolFilter();
BoolFilterBuilder tagsAndNothingElse = typesNotSources.must(FilterBuilders.termsFilter(DocumentPojo.tags_, invTagEl.getValue().toArray()));
if (null != score.sourceWeights) {
tagsAndNothingElse = tagsAndNothingElse.mustNot(FilterBuilders.termsFilter(DocumentPojo.sourceKey_, score.sourceWeights.keySet().toArray()));
}
if (null != score.typeWeights) {
tagsAndNothingElse = tagsAndNothingElse.mustNot(FilterBuilders.termsFilter(DocumentPojo.mediaType_, score.typeWeights.keySet().toArray()));
}
manualWeights.add(tagsAndNothingElse, invTagEl.getKey());
}
}
}//TESTED