1. Su Lab
  2. BioThings
  3. mygene.info

Commits

Cyrus Afrasiabi  committed 77cdba1

Added /metadata/fields to mygene. Changed query output from _get_genedoc to _get_genedoc_2. Renamed _clean_res2 to _cleaned_res_3.

Comments (0)

Files changed (2)

File src/index.py Modified

View file
  • Ignore whitespace
  • Hide word diff
 from api_v1.handlers import APP_LIST as api_v1_app_list
 from api_v2.handlers import APP_LIST as api_v2_app_list
 from api_v2.handlers import MetaDataHandler
+from api_v2.handlers import FieldsHandler
 #from api_v2.handlers_async import APP_LIST as api_v2_async_app_list
 from demo.handlers import APP_LIST as demo_app_list
 #from auth.handlers import APP_LIST as auth_app_list
     (r"/status", StatusCheckHandler),
     (r"/metadata", MetaDataHandler),
     (r"/v2a/metadata", MetaDataHandler),
+    (r"/metadata/fields", FieldsHandler),
 ]
 
 APP_LIST += add_apps('', api_v2_app_list)

File src/utils/es.py Modified

View file
  • Ignore whitespace
  • Hide word diff
         # self._doc_type = 'gene'
         self._index = ES_INDEX_NAME_ALL
         self._doc_type = ES_INDEX_TYPE
-        
+
         # Scroll setup
         self._scroll_time = '1m'
         self._total_scroll_size = 1000
         else:
             return [self._get_genedoc(hit, dotfield=dotfield) for hit in hits['hits']]
 
-    def _clean_res2(self, res):
-        ''' res is the dictionary returned from a query.
-            do some reformating of raw ES results before returning.
-
-            This method is used for self.query method.
-        '''
-        _res = res['hits']
-        for attr in ['took', 'facets', 'aggregations', '_scroll_id']:
-            if attr in res:
-                _res[attr] = res[attr]
-        _res['hits'] = [self._get_genedoc(hit) for hit in _res['hits']]
-        return _res
-
-
     def _cleaned_res_2(self, res, empty=[], error={'error': True},
                        single_hit=False, dotfield=True, fields=None):
         if 'error' in res:
                                         dotfield=dotfield, fields=fields)
                     for hit in hits['hits']]
 
+    def _cleaned_res_3(self, res):
+        ''' res is the dictionary returned from a query.
+            do some reformating of raw ES results before returning.
+
+            This method is used for self.query method.
+        '''
+        _res = res['hits']
+        for attr in ['took', 'facets', 'aggregations', '_scroll_id']:
+            if attr in res:
+                _res[attr] = res[attr]
+        _res['hits'] = [self._get_genedoc_2(hit) for hit in _res['hits']]
+        return _res
+
     def _cleaned_scopes(self, scopes):
         '''return a cleaned scopes parameter.
             should be either a string or a list of scope fields.
                 return {'success': False, 'error': msg}
 
             if not options.raw:
-                res = self._clean_res2(res)
+                res = self._cleaned_res_3(res)
                 #_res = res['hits']
                 #_res['took'] = res['took']
                 #if "facets" in res:
             return {'success': False, 'error': 'No results to return.'}
         else:
             if not options.raw:
-                res = self._clean_res2(r)
+                res = self._cleaned_res_3(r)
         #res.update({'_scroll_id': scroll_id})
         if r['_shards']['failed']:
             res.update({'_warning': 'Scroll request has failed on {} shards out of {}.'.format(r['_shards']['failed'], r['_shards']['total'])})