Pārlūkot izejas kodu

[search] Map works with country codes

Romain Rigaux 11 gadi atpakaļ
vecāks
revīzija
f584a9d

+ 5 - 2
apps/search/src/search/api.py

@@ -191,12 +191,15 @@ class SolrApi(BaseSolrApi):
              ('facet.range', '{!ex=%s}%s' % (facet['field'], facet['field'])),
              ('f.%s.facet.range.start' % facet['field'], facet['properties']['start']),
              ('f.%s.facet.range.end' % facet['field'], facet['properties']['end']),
-             ('f.%s.facet.range.gap' % facet['field'], facet['properties']['gap']),]
+             ('f.%s.facet.range.gap' % facet['field'], facet['properties']['gap']),
+             ('f.%s.facet.mincount' % facet['field'], facet['properties']['gap'], facet['properties']['mincount']),]
           )          
         elif facet['type'] == 'field':
           params += (
               ('facet.field', '{!ex=%s}%s' % (facet['field'], facet['field'])),
-              ('f.%s.facet.limit' % facet['field'], int(facet['properties'].get('limit', 10)) + 1))
+              ('f.%s.facet.limit' % facet['field'], int(facet['properties'].get('limit', 10)) + 1),
+              ('f.%s.facet.mincount' % facet['field'], int(facet['properties']['mincount'])),
+          )
 
     for fq in query['fqs']:
       if fq['type'] == 'field':        

+ 2 - 17
apps/search/src/search/models.py

@@ -456,23 +456,8 @@ def get_facet_field_label(field, facets):
   facets = filter(lambda facet: facet['type'] == 'field' and facet['field'] == field, facets)
   if facets:
     return facets[0]['label']
-#  if type == 'field':
-#    for fld in facets['fields']:
-#      if fld['field'] == field:
-#        label = fld['label']
-#  elif type == 'range':
-#    for fld in facets['ranges']:
-#      if fld['field'] == field:
-#        label = fld['label']
-#  elif type == 'date':
-#    for fld in facets['dates']:
-#      if fld['field'] == field:
-#        label = fld['label']
-#  elif type == 'chart':
-#    for fld in facets['charts']:
-#      if fld['field'] == field:
-#        label = fld['label']
-  return label
+  else:
+    return label
 
 def get_facet_field_uuid(field, type, facets):
   uuid = ''

+ 5 - 3
apps/search/src/search/templates/search2.mako

@@ -796,7 +796,9 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
   <!-- ko if: $root.getFacetFromQuery(id()) -->
   <div class="row-fluid" data-bind="with: $root.getFacetFromQuery(id())">
     <div data-bind="visible: $root.isEditing, with: $root.collection.getFacetById($parent.id())" style="margin-bottom: 20px">
-      ${ _('Label') }: <input type="text" data-bind="value: label" />
+      ${ _('Scope') }: <input type="text" data-bind="value: properties.scope" />
+      <span data-bind="template: { name: 'facet-toggle' }">
+      </span>
     </div>
     <div data-bind="with: $root.collection.getFacetById($parent.id())">
       <div data-bind="mapChart: {data: {counts: $parent.counts, widget_id: $parent.id},
@@ -1753,9 +1755,9 @@ $(document).ready(function () {
   var selectedWidget = null;
   function showAddFacetDemiModal(widget) {
     if (["resultset-widget", "html-resultset-widget", "filter-widget"].indexOf(widget.widgetType()) == -1) {      
-      viewModel.collection.template.fieldsModalFilter();
-      viewModel.collection.template.fieldsModalType(widget.widgetType());
       viewModel.collection.template.fieldsModalFilter("");
+      viewModel.collection.template.fieldsModalType(widget.widgetType());
+      viewModel.collection.template.fieldsModalFilter.valueHasMutated();
       viewModel.collection.template.fieldsModalOkButton(false);
       $('#addFacetInput').typeahead({
           'source': viewModel.collection.template.availableWidgetFieldsNames(), 

+ 6 - 7
apps/search/src/search/views.py

@@ -108,14 +108,11 @@ def search(request):
 
   if collection['id']:
     hue_collection = Collection.objects.get(id=collection['id']) # TODO perms
-
-  print request.POST
     
   if collection:
     try:      
       response = SolrApi(SOLR_URL.get(), request.user).query2(collection, query)
       response = augment_solr_response2(response, collection, query)
-      print response
     except RestException, e:
       try:
         response['error'] = json.loads(e.message)['error']['msg']
@@ -631,8 +628,8 @@ def new_facet(request):
       'canRange': False,
       'stacked': False,
       'limit': 10,
-      'mincount': 0, # Not used yet
-      'andUp': False,
+      'mincount': 0,
+      'andUp': False,  # Not used yet
     }
     
     solr_api = SolrApi(SOLR_URL.get(), request.user)
@@ -646,8 +643,10 @@ def new_facet(request):
     else:
       facet_type = 'field'        
         
-    if facet_type == 'map-widget':
-      properties['scope'] = 'world'        
+    if widget_type == 'map-widget':
+      properties['scope'] = 'world'
+      properties['mincount'] = 1
+      properties['limit'] = 100        
         
     result['message'] = ''
     result['facet'] = {

+ 24 - 18
apps/search/static/js/charts.ko.js

@@ -105,11 +105,11 @@ ko.bindingHandlers.mapChart = {
       }
     }
 
-    $(element).height($(element).width()/2.23);
+    $(element).height($(element).width() / 2.23);
 
     var _data = _options.transformer(_options.data);
     var _maxWeight = 0;
-    $(_data).each(function(cnt, item){
+    $(_data).each(function(cnt, item) {
       if (item.value > _maxWeight) _maxWeight = item.value;
     });
 
@@ -119,19 +119,21 @@ ko.bindingHandlers.mapChart = {
     var _maphovers = {};
     var _fills = {};
     var _noncountries = [];
+
     if (_options.isScale){
       _fills["defaultFill"] = HueColors.LIGHT_BLUE;
       var _colors = HueColors.scale(HueColors.LIGHT_BLUE, HueColors.DARK_BLUE, _data.length);
-      $(_colors).each(function(cnt, item){
+      $(_colors).each(function(cnt, item) {
         _fills["fill_" + cnt] = item;
       });
-      $(_data).each(function(cnt, item){
-        var _country = HueGeo.getCountryFromName(item.label);
-        if (_country != null){
-          _mapdata[_country.alpha3] = {
-            fillKey: "fill_" + Math.floor(item.value/_chunk)
+      $(_data).each(function(cnt, item) {
+        var _place = item.label;
+        if (_place != null){
+          _mapdata[_place] = {
+            fillKey: "fill_" + Math.floor(item.value / _chunk),
+            id: _place
           };
-          _maphovers[_country.name.split(",")[0].toLowerCase()] = item.value;
+          _maphovers[_place] = item.value;
         }
         else {
           _noncountries.push(item);
@@ -142,12 +144,13 @@ ko.bindingHandlers.mapChart = {
       _fills["defaultFill"] = HueColors.BLUE;
       _fills["selected"] = HueColors.DARK_BLUE;
       $(_data).each(function(cnt, item){
-        var _country = HueGeo.getCountryFromName(item.label);
-        if (_country != null){
-          _mapdata[_country.alpha3] = {
-            fillKey: "selected"
+    	var _place = item.label;
+        if (_place != null){
+          _mapdata[_place] = {
+            fillKey: "selected",
+            id: _place
           };
-          _maphovers[_country.name.split(",")[0].toLowerCase()] = item.value;
+          _maphovers[_place] = item.value;
         }
         else {
           _noncountries.push(item);
@@ -156,7 +159,7 @@ ko.bindingHandlers.mapChart = {
     }
 
     var _map = null;
-    function createDatamap(element, options, fills, mapData, nonCountries, mapHovers){
+    function createDatamap(element, options, fills, mapData, nonCountries, mapHovers) {
       _map = new Datamap({
         element: element,
         fills: fills,
@@ -199,8 +202,11 @@ ko.bindingHandlers.mapChart = {
           highlightFillColor: HueColors.DARK_BLUE,
           highlightBorderColor: HueColors.DARK_BLUE,
           popupTemplate: function(geography, data) {
-            var _hover = mapHovers[geography.properties.name.toLowerCase()];
-            return '<div class="hoverinfo" style="text-align: center"><strong>' + geography.properties.name + '</strong>' + ((typeof _hover != "undefined")?'<br/>' + _hover : '') + '</div>'
+        	var _hover = '';
+        	if (data != null) {
+        	  _hover = '<br/>' + mapHovers[data.id];	
+        	}            
+            return '<div class="hoverinfo" style="text-align: center"><strong>' + geography.properties.name + '</strong>' + _hover + '</div>'
           }
         }
       });
@@ -219,7 +225,7 @@ ko.bindingHandlers.mapChart = {
           $(element).width(_max);
         }
       }
-      $(element).height($(element).width()/2.23);
+      $(element).height($(element).width() / 2.23);
       createDatamap(element, _options, _fills, _mapdata, _noncountries, _maphovers)
     });
   },

+ 1 - 1
apps/search/static/js/search.ko.js

@@ -492,7 +492,7 @@ var Collection = function (vm, collection) {
     return _field;    
   };
 
-  self.template.fieldsModalFilter = ko.observable(); // For UI
+  self.template.fieldsModalFilter = ko.observable(""); // For UI
   self.template.fieldsModalType = ko.observable(""); // For UI
   self.template.fieldsAttributesFilter = ko.observable(""); // For UI
   self.template.fieldsModalOkButton = ko.observable(false);