Use the sentiment aggregation value if present
This commit is contained in:
parent
d8cb3a263b
commit
fd47a3ddc8
|
@ -602,24 +602,28 @@ class ElasticsearchBackend(StorageBackend):
|
|||
if isinstance(sentiment_r, dict):
|
||||
return sentiment_r
|
||||
if sentiment_r:
|
||||
if rule_object is not None:
|
||||
sentiment_index = "meta.aggs.avg_sentiment.value"
|
||||
else:
|
||||
sentiment_index = "sentiment"
|
||||
sentiment_method, sentiment = sentiment_r
|
||||
range_query_compare = {"range": {"sentiment": {}}}
|
||||
range_query_compare = {"range": {sentiment_index: {}}}
|
||||
range_query_precise = {
|
||||
"match": {
|
||||
"sentiment": None,
|
||||
sentiment_index: None,
|
||||
}
|
||||
}
|
||||
if sentiment_method == "below":
|
||||
range_query_compare["range"]["sentiment"]["lt"] = sentiment
|
||||
range_query_compare["range"][sentiment_index]["lt"] = sentiment
|
||||
add_top.append(range_query_compare)
|
||||
elif sentiment_method == "above":
|
||||
range_query_compare["range"]["sentiment"]["gt"] = sentiment
|
||||
range_query_compare["range"][sentiment_index]["gt"] = sentiment
|
||||
add_top.append(range_query_compare)
|
||||
elif sentiment_method == "exact":
|
||||
range_query_precise["match"]["sentiment"] = sentiment
|
||||
range_query_precise["match"][sentiment_index] = sentiment
|
||||
add_top.append(range_query_precise)
|
||||
elif sentiment_method == "nonzero":
|
||||
range_query_precise["match"]["sentiment"] = 0
|
||||
range_query_precise["match"][sentiment_index] = 0
|
||||
add_top_negative.append(range_query_precise)
|
||||
|
||||
# Add in the additional information we already populated
|
||||
|
|
|
@ -81,15 +81,21 @@ def make_graph(results):
|
|||
graph = []
|
||||
for index, item in enumerate(results):
|
||||
date = str(index)
|
||||
sentiment = None
|
||||
if "meta" in item:
|
||||
if "aggs" in item["meta"]:
|
||||
if "avg_sentiment" in item["meta"]["aggs"]:
|
||||
sentiment = item["meta"]["aggs"]["avg_sentiment"]["value"]
|
||||
else:
|
||||
if "sentiment" in item:
|
||||
sentiment = item["sentiment"]
|
||||
graph.append(
|
||||
{
|
||||
"text": item.get("words_noun", None)
|
||||
or item.get("msg", None)
|
||||
or item.get("id"),
|
||||
"text": item.get("msg", None) or item.get("id"),
|
||||
"nick": item.get("nick", None),
|
||||
"channel": item.get("channel", None),
|
||||
"net": item.get("net", None),
|
||||
"value": item.get("sentiment", None) or None,
|
||||
"value": sentiment,
|
||||
"date": date,
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue