Răsfoiți Sursa

HUE-1975 [search] Add the dynamic fields from the Solr API

We now get all the standard fields (like before) + the
genric field instances from the index as list of possible fields.

Update the download icons
Add a test
Update the test mocks
Romain Rigaux 11 ani în urmă
părinte
comite
e76e95c

+ 25 - 10
apps/search/src/search/api.py

@@ -50,6 +50,17 @@ class SolrApi(object):
       return (('doAs', self._user ),)
     return (('user.name', DEFAULT_USER), ('doAs', self._user),)
 
+  def _get_json(self, response):
+    if type(response) != dict:
+      # Got 'plain/text' mimetype instead of 'application/json'
+      try:
+        response = json.loads(response)
+      except ValueError, e:
+        # Got some null bytes in the response
+        LOG.error('%s: %s' % (unicode(e), repr(response)))
+        response = json.loads(response.replace('\x00', ''))
+    return response
+
   def query(self, solr_query, hue_core):
     try:
       params = self._get_params() + (
@@ -67,16 +78,7 @@ class SolrApi(object):
           params += (('fq', fq),)
 
       response = self._root.get('%(collection)s/select' % solr_query, params)
-
-      if type(response) != dict:
-        # Got 'plain/text' mimetype instead of 'application/json'
-        try:
-          response = json.loads(response)
-        except ValueError, e:
-          # Got some null bytes in the response
-          LOG.error('%s: %s' % (unicode(e), repr(response)))
-          response = json.loads(response.replace('\x00', ''))
-      return response
+      return self._get_json(response)
     except RestException, e:
       raise PopupException(e, title=_('Error while accessing Solr'))
 
@@ -145,3 +147,16 @@ class SolrApi(object):
       return self._root.get('%(core)s/admin/file' % {'core': core}, params=params)
     except RestException, e:
       raise PopupException(e, title=_('Error while accessing Solr'))
+
+  def fields(self, core, dynamic=False):
+    try:
+      params = self._get_params() + (
+          ('wt', 'json'),
+          ('fl', '*'),
+      )
+      if not dynamic:
+        params += (('show', 'schema'),)
+      response = self._root.get('%(core)s/admin/luke' % {'core': core}, params=params)
+      return self._get_json(response)
+    except RestException, e:
+      raise PopupException(e, title=_('Error while accessing Solr'))

+ 10 - 6
apps/search/src/search/models.py

@@ -16,7 +16,6 @@
 # limitations under the License.
 
 
-import itertools
 import json
 import logging
 import re
@@ -285,14 +284,19 @@ class Collection(models.Model):
     return reverse('search:admin_collection', kwargs={'collection_id': self.id})
 
   def fields(self, user):
-    return sorted([field.get('name') for field in self.fields_data(user)])
+    return sorted([str(field.get('name', '')) for field in self.fields_data(user)])
 
   def fields_data(self, user):
-    solr_schema = SolrApi(SOLR_URL.get(), user).schema(self.name)
-    schema = etree.fromstring(solr_schema)
+    schema_fields = SolrApi(SOLR_URL.get(), user).fields(self.name)
+    schema_fields = schema_fields['schema']['fields']
 
-    return sorted([{'name': field.get('name'), 'type': field.get('type')}
-                   for fields in schema.iter('fields') for field in itertools.chain(fields.iter('field'), fields.iter('dynamicField'))])
+    dynamic_fields = SolrApi(SOLR_URL.get(), user).fields(self.name, dynamic=True)
+    dynamic_fields = dynamic_fields['fields']
+
+    schema_fields.update(dynamic_fields)
+
+    return sorted([{'name': str(field), 'type': str(attributes.get('type', ''))}
+                  for field, attributes in schema_fields.iteritems()])
 
   @property
   def properties_dict(self):

+ 3 - 2
apps/search/src/search/templates/search.mako

@@ -28,6 +28,7 @@ import time
 ${ commonheader(_('Search'), "search", user, "90px") | n,unicode }
 
 <link rel="stylesheet" href="/search/static/css/search.css">
+<link href="/static/ext/css/hue-filetypes.css" rel="stylesheet">
 <script src="/static/ext/js/moment.min.js" type="text/javascript" charset="utf-8"></script>
 <script src="/search/static/js/search.utils.js" type="text/javascript" charset="utf-8"></script>
 <script src="/static/ext/js/jquery/plugins/jquery.flot.min.js" type="text/javascript" charset="utf-8"></script>
@@ -85,8 +86,8 @@ ${ commonheader(_('Search'), "search", user, "90px") | n,unicode }
       <div class="btn-group download-btn-group" style="margin-left: 15px">
         <button type="button" id="download-btn" class="btn btn-inverse dropdown-toggle" data-toggle="dropdown"><i class="fa fa-download"></i></button>
         <ul class="dropdown-menu" role="menu">
-          <li><a href="javascript:void(0)" id="download-csv"><i class="fa fa-list"></i>&nbsp; CSV</a></li>
-          <li><a href="javascript:void(0)" id="download-xls"><i class="fa fa-th"></i>&nbsp; XLS</a></li>
+          <li><a href="javascript:void(0)" id="download-xls"><i class="hfo hfo-file-xls"></i>&nbsp; ${ _('XLS') }</a></li>
+          <li><a href="javascript:void(0)" id="download-csv"><i class="hfo hfo-file-csv">&nbsp; ${ _('CSV') }</i></a></li>
         </ul>
       </div>
       % endif

Fișier diff suprimat deoarece este prea mare
+ 8 - 0
apps/search/src/search/tests.py


Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff