in core/src/main/java/org/apache/sdap/mudrod/recommendation/process/FeatureBasedSimilarity.java [174:214]
private void normalizeVariableWeight(ESDriver es) {
es.createBulkProcessor();
double totalWeight = 0.0;
for (String variable : variableWeights.keySet()) {
totalWeight += variableWeights.get(variable);
}
SearchResponse scrollResp = es.getClient().prepareSearch(indexName).setTypes(variableSimType).setScroll(new TimeValue(60000)).setQuery(QueryBuilders.matchAllQuery()).setSize(100).execute()
.actionGet();
while (true) {
for (SearchHit hit : scrollResp.getHits().getHits()) {
Map<String, Object> similarities = hit.getSource();
double totalSim = 0.0;
for (String variable : variableWeights.keySet()) {
if (similarities.containsKey(variable + "_Sim")) {
double value = (double) similarities.get(variable + "_Sim");
double weight = variableWeights.get(variable);
totalSim += weight * value;
}
}
double weight = 0.0;
if(totalWeight != 0){
weight = totalSim / totalWeight;
}
UpdateRequest ur = es.generateUpdateRequest(indexName, variableSimType, hit.getId(), "weight", weight);
es.getBulkProcessor().add(ur);
}
scrollResp = es.getClient().prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
if (scrollResp.getHits().getHits().length == 0) {
break;
}
}
es.destroyBulkProcessor();
}