Commit b14caa10 authored by Alberto Pascual's avatar Alberto Pascual
Browse files

new version without elasticsearch

parent bab8311a
......@@ -3,6 +3,7 @@
"authors": [
"gsi-upm"
],
"version" : "1.0.1",
"description": "Web Component designed to visualize entities present in Tweets",
"main": "entities-chart.html",
"keywords": [
......
......@@ -116,7 +116,8 @@
}
.tag span{
position: relative;
top:-10px;
top:0px;
margin-right: 2px;
}
</style>
......@@ -128,7 +129,7 @@
<span>{{title}}</span>
</div>
<div id="tag-wrapper">
<template is="dom-repeat" items="{{data}}" as="entity">
<template is="dom-repeat" items="{{entities}}" as="entity">
<paper-button class="tag active" on-tap="filter"><span>{{entity.0}}</span><span class="number">{{entity.1}}</span></paper-button>
</template>
</div>
......@@ -151,13 +152,16 @@
properties: {
data: {
type: Array,
value: [{"name":"Amazon", "reviews":11},{"name":"Vodafone", "reviews":35}, {"name":"Google", "reviews":72}, {"name":"Santander", "reviews":9}, {"name":"Apple", "reviews":10}] //default value for data array.
},
type: Object,
observer: '_dataChanged'
},
icon: {
type: String
},
entities: {
type: Array
},
title: {
type: String,
......@@ -202,149 +206,30 @@
}
},
observers: [
'_filtersChange(filters.*)'
],
ready: function() {
this.field ? this.queryDefault() : undefined
},
removeFilters: function(){
this.filters = [];
},
queryDefault: function() {
var client = new $.es.Client({
hosts: this.host
});
_dataChanged: function() {
var that = this
client.search({
// undocumented params are appended to the query string
index: this.index,
type: this.subindex,
body: {
size: 10,
query: {
match_all: {}
},
aggs: {
rest: {
terms: {
field: this.field,
size: 10,
order: {
_count: "desc"
}
}
}
}
var aggs = 0
try{
var hits = this.data.aggregations[this.field].buckets;
}
}).then(function (resp) {
var hits = resp.aggregations.rest.buckets;
var results = []
hits.forEach(function(entry) {
results.push([entry.key, entry.doc_count]);
});
that.data = results
filtered = true;
});
},
queryChange: function(value) {
var client = new $.es.Client({
hosts: this.host
});
var that = this
client.search({
// undocumented params are appended to the query string
index: this.index,
type: this.subindex,
body: {
size: 10,
query: {
multi_match:{
query: this.query,
fields: this.fields
}
},
aggs: {
rest: {
terms: {
field: this.field,
size: 10,
order: {
_count: "desc"
}
}
}
}
}
}).then(function (resp) {
var hits = resp.aggregations.rest.buckets;
var results = []
hits.forEach(function(entry) {
results.push([entry.key, entry.doc_count]);
});
that.data = results
catch(err){
var hits = []
}
var data = [];
hits.forEach(function(entry) {
data.push([entry.key.toUpperCase(), entry.doc_count]);
});
that.entities = data;
filtered = true;
},
/** Fired when a search is made.
*
* @event query-change
* @param {Object} detail
* @param {Object} detail.query The search string.
*/
_queryChanged: function() {
this.query ? this.queryChange(this.query) : this.queryDefault();
removeFilters: function(){
this.filters = [];
},
_filtersChange: function() {
if(filtered){
var client = new $.es.Client({
hosts: this.host
});
var that = this
client.search({
// undocumented params are appended to the query string
index: this.index,
type: this.subindex,
body: {
size: 10,
query: {
bool: {
must: this.filters,
}
},
aggs: {
rest: {
terms: {
field: this.field,
size: 10,
order: {
_count: "desc"
}
}
}
}
}
}).then(function (resp) {
var hits = resp.aggregations.rest.buckets;
var results = []
hits.forEach(function(entry) {
results.push([entry.key, entry.doc_count]);
});
that.data = results
});
filter: function(e) {
this.push('filters', { term: { name: e.model.__data__.entity[0].toLowerCase()}})
}
},
filter: function(e) {
this.push('filters', { term: { name: e.model.__data__.entity[0]}})
}
});
</script>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment