Browse Source

HUE-3294 [desktop] Add backend document search for documents in assist

Romain Rigaux 9 năm trước cách đây
mục cha
commit
9429861d59

+ 67 - 2
desktop/core/src/desktop/api2.py

@@ -118,6 +118,36 @@ def search_documents(request):
   return JsonResponse(response)
   return JsonResponse(response)
 
 
 
 
+def _search(user, perms='both', include_history=False, include_trashed=False, include_managed=False, search_text=None):
+  response = {
+    'documents': []
+  }
+
+  documents = Document2.objects.documents(
+    user=user,
+    perms=perms,
+    include_history=include_history,
+    include_trashed=include_trashed,
+    include_managed=include_managed
+  )
+
+  type_filters = None
+  sort = '-last_modified'
+  search_text = search_text
+  flatten = True
+
+  page = 1
+  limit = 25
+
+  # Refine results
+  response.update(__filter_documents(type_filters, sort, search_text, queryset=documents, flatten=flatten))
+
+  # Paginate
+  response.update(__paginate(page, limit, queryset=response['documents']))
+
+  return response
+
+
 @api_error_handler
 @api_error_handler
 def get_document(request):
 def get_document(request):
   """
   """
@@ -503,11 +533,37 @@ def _update_imported_oozie_document(doc, uuids_map):
   return doc
   return doc
 
 
 def search_entities(request):
 def search_entities(request):
-  return metadata_search_entities(request)
+  sources = json.loads(request.POST.get('sources')) or []
+
+  if 'documents' in sources:
+    search_text = json.loads(request.POST.get('query_s', ''))
+    entities = _search(user=request.user, search_text=search_text)
+    response = {
+      'entities': [{'hue_name': e.name, 'hue_description': e.description, 'type': 'HUE', 'originalName': e.name, 'link': '/home?uuid=%s' % e.uuid} for e in entities['documents']],
+      'count': len(entities['documents']),
+      'status': 0
+    }
+
+    return JsonResponse(response)
+  else:
+    return metadata_search_entities(request)
 
 
 
 
 def search_entities_interactive(request):
 def search_entities_interactive(request):
-  return metadata_search_entities_interactive(request)
+  sources = json.loads(request.POST.get('sources')) or []
+
+  if 'documents' in sources:
+    search_text = json.loads(request.POST.get('query_s', ''))
+    entities = _search(user=request.user, search_text=search_text)
+    response = {
+      'results': [{'hue_name': e.name, 'hue_description': e.description, 'type': 'HUE', 'originalName': e.name} for e in entities['documents']],
+      'count': len(entities['documents']),
+      'status': 0
+    }
+
+    return JsonResponse(response)
+  else:
+    return metadata_search_entities_interactive(request)
 
 
 
 
 def _is_import_valid(documents):
 def _is_import_valid(documents):
@@ -644,6 +700,10 @@ def _filter_documents(request, queryset, flatten=True):
   sort = request.GET.get('sort', '-last_modified')
   sort = request.GET.get('sort', '-last_modified')
   search_text = request.GET.get('text', None)
   search_text = request.GET.get('text', None)
 
 
+  return __filter_documents(type_filters, sort, search_text, queryset, flatten)
+
+
+def __filter_documents(type_filters, sort, search_text, queryset, flatten=True):
   documents = queryset.search_documents(
   documents = queryset.search_documents(
       types=type_filters,
       types=type_filters,
       search_text=search_text,
       search_text=search_text,
@@ -674,6 +734,11 @@ def _paginate(request, queryset):
   page = int(request.GET.get('page', 1))
   page = int(request.GET.get('page', 1))
   limit = int(request.GET.get('limit', 0))
   limit = int(request.GET.get('limit', 0))
 
 
+  return __paginate(page, limit, queryset)
+
+
+def __paginate(page, limit, queryset):
+
   if limit > 0:
   if limit > 0:
     offset = (page - 1) * limit
     offset = (page - 1) * limit
     last = offset + limit
     last = offset + limit

+ 11 - 5
desktop/core/src/desktop/templates/assist.mako

@@ -860,6 +860,9 @@ from metadata.conf import has_navigator
         <span>${ _('Error loading contents.') }</span>
         <span>${ _('Error loading contents.') }</span>
       </div>
       </div>
       <!-- /ko -->
       <!-- /ko -->
+      <!-- ko with: $parents[1] -->
+      <!-- ko template: { if: searchActive() && searchInput() !== '' && navigatorEnabled(), name: 'nav-search-result' } --><!-- /ko -->
+      <!-- /ko -->
     </div>
     </div>
   </script>
   </script>
 
 
@@ -1686,7 +1689,8 @@ from metadata.conf import has_navigator
         'FILE': 'fa-file-o',
         'FILE': 'fa-file-o',
         'SUB_OPERATION': 'fa-code-fork',
         'SUB_OPERATION': 'fa-code-fork',
         'COLLECTION': 'fa-search',
         'COLLECTION': 'fa-search',
-        'HBASE': 'fa-th-large'
+        'HBASE': 'fa-th-large',
+        'HUE': 'fa-file-o'
       };
       };
 
 
       /**
       /**
@@ -1768,7 +1772,8 @@ from metadata.conf import has_navigator
               name: '${ _("S3") }',
               name: '${ _("S3") }',
               type: 's3',
               type: 's3',
               icon: 'fa-cubes',
               icon: 'fa-cubes',
-              minHeight: 50
+              minHeight: 50,
+              showNavSearch: false
             }));
             }));
           }
           }
 
 
@@ -1780,7 +1785,8 @@ from metadata.conf import has_navigator
             name: '${ _("Collections") }',
             name: '${ _("Collections") }',
             type: 'collections',
             type: 'collections',
             icon: 'fa-search-plus',
             icon: 'fa-search-plus',
-            minHeight: 50
+            minHeight: 50,
+            showNavSearch: false
           }));
           }));
 
 
           self.availablePanels.push(new AssistInnerPanel({
           self.availablePanels.push(new AssistInnerPanel({
@@ -1791,7 +1797,8 @@ from metadata.conf import has_navigator
             name: '${ _("HBase") }',
             name: '${ _("HBase") }',
             type: 'hbase',
             type: 'hbase',
             icon: 'fa-th-large',
             icon: 'fa-th-large',
-            minHeight: 50
+            minHeight: 50,
+            showNavSearch: false
           }));
           }));
 
 
           self.availablePanels.push(new AssistInnerPanel({
           self.availablePanels.push(new AssistInnerPanel({
@@ -1805,7 +1812,6 @@ from metadata.conf import has_navigator
             type: 'documents',
             type: 'documents',
             icon: 'fa-files-o',
             icon: 'fa-files-o',
             minHeight: 50,
             minHeight: 50,
-            showNavSearch: false,
             visible: params.visibleAssistPanels && params.visibleAssistPanels.indexOf('documents') !== -1
             visible: params.visibleAssistPanels && params.visibleAssistPanels.indexOf('documents') !== -1
           }));
           }));
         }
         }