Эх сурвалжийг харах

[search] Support collections or just core

Romain Rigaux 12 жил өмнө
parent
commit
b2fb177d6b

+ 1 - 1
apps/search/src/search/api.py

@@ -98,7 +98,7 @@ class SolrApi(object):
 
   def cores(self):
     try:
-      return self._root.get('admin/cores', params={'wt': 'json'})
+      return self._root.get('admin/cores', params={'wt': 'json'})['status']
     except RestException, e:
       raise PopupException('Error while accessing Solr: %s' % e)
 

+ 9 - 2
apps/search/src/search/search_controler.py

@@ -48,8 +48,9 @@ class SearchController(object):
     return solr_collections
 
   def get_new_cores(self):
-    # TODO
-    solr_cores = []
+    solr_cores = SolrApi(SOLR_URL.get()).cores()
+    for name in Collection.objects.values_list('name', flat=True):
+      solr_cores.pop(name, None)
 
     return solr_cores
 
@@ -60,5 +61,11 @@ class SearchController(object):
 
       hue_collection, created = Collection.objects.get_or_create(name=attrs['name'], solr_properties=collection, is_enabled=True)
       return hue_collection
+    elif attrs['type'] == 'core':
+      cores = self.get_new_cores()
+      core = cores[attrs['name']]
+
+      hue_collection, created = Collection.objects.get_or_create(name=attrs['name'], solr_properties=core, is_enabled=True, is_core_only=True)
+      return hue_collection      
     else:
       raise PopupException(_('Collection type does not exit: %s') % attrs)

+ 0 - 113
apps/search/src/search/templates/admin.mako

@@ -1,113 +0,0 @@
-## Licensed to Cloudera, Inc. under one
-## or more contributor license agreements.  See the NOTICE file
-## distributed with this work for additional information
-## regarding copyright ownership.  Cloudera, Inc. licenses this file
-## to you under the Apache License, Version 2.0 (the
-## "License"); you may not use this file except in compliance
-## with the License.  You may obtain a copy of the License at
-##
-##     http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-
-<%!
-  from desktop.views import commonheader, commonfooter
-  from django.utils.translation import ugettext as _
-%>
-
-<%namespace name="macros" file="macros.mako" />
-<%namespace name="actionbar" file="actionbar.mako" />
-
-${ commonheader(_('Manage collections'), "search", user) | n,unicode }
-
-<link rel="stylesheet" href="/search/static/css/admin.css">
-
-<div class="container-fluid">
-
-  <h1>${_('Search Admin - Collections')}</h1>
-  <%actionbar:render>
-    <%def name="search()">
-      <input type="text" placeholder="${_('Filter collections by name...')}" class="input-xxlarge search-query" id="filterInput">
-    </%def>
-
-  </%actionbar:render>
-  <div class="row-fluid">
-    <div class="span12">
-      <ul id="collections">
-      % for collection in hue_collections:
-        <li style="cursor: move" data-collection="${ collection.name }">
-          <a href="${ collection.get_absolute_url() }" class="pull-right" style="margin-top: 10px;margin-right: 10px"><i class="icon-edit"></i> ${_('Edit')}</a>
-          <h4><i class="icon-list"></i> ${ collection.name }</h4>
-        </li>
-      % endfor
-      </ul>
-    </div>
-  </div>
-</div>
-
-<style type="text/css">
-  #collections {
-    list-style-type: none;
-    margin: 0;
-    padding: 0;
-    width: 100%;
-  }
-
-  #collections li {
-    margin-bottom: 10px;
-    padding: 10px;
-    border: 1px solid #E3E3E3;
-    height: 40px;
-  }
-
-  .placeholder {
-    height: 40px;
-    background-color: #F5F5F5;
-    border: 1px solid #E3E3E3;
-  }
-</style>
-
-<script src="/static/ext/js/jquery/plugins/jquery-ui-draggable-droppable-sortable-1.8.23.min.js"></script>
-
-<script type="text/javascript">
-  $(document).ready(function () {
-    var orderedCores;
-    serializeList();
-    $("#collections").sortable({
-      placeholder: "placeholder",
-      update: function (event, ui) {
-        serializeList();
-        ##TODO: serialize via ajax the order of collections
-        ## the array is: orderedCores
-        ## console.log(orderedCores)
-      }
-    });
-    $("#collections").disableSelection();
-
-    function serializeList() {
-      orderedCores = [];
-      $("#collections li").each(function () {
-        orderedCores.push($(this).data("collection"));
-      });
-    }
-
-    var filter = -1;
-    $("#filterInput").on("keyup", function () {
-      clearTimeout(filter);
-      filter = window.setTimeout(function () {
-        $("#collections li").removeClass("hide");
-        $("#collections li").each(function () {
-          if ($(this).data("collection").toLowerCase().indexOf($("#filterInput").val().toLowerCase()) == -1) {
-            $(this).addClass("hide");
-          }
-        });
-      }, 300);
-    });
-  });
-</script>
-
-${ commonfooter(messages) | n,unicode }

+ 4 - 2
apps/search/src/search/templates/admin_collections.mako

@@ -27,19 +27,21 @@ ${ commonheader(_('Search'), "search", user) | n,unicode }
 <link rel="stylesheet" href="/search/static/css/admin.css">
 
 <div class="container-fluid">
-  <h1>${_('Search Admin - Cores')}</h1>
+  <h1>${_('Indexes')}</h1>
+
   <%actionbar:render>
     <%def name="search()">
       <input type="text" placeholder="${_('Filter collections by name...')}" class="input-xxlarge search-query" id="filterInput">
     </%def>
   </%actionbar:render>
+
   <div class="row-fluid">
     <div class="span12">
       <ul id="collections">
       % for collection in hue_collections:
         <li style="cursor: move" data-collection="${ collection.name }">
           <a href="${ collection.get_absolute_url() }" class="pull-right" style="margin-top: 10px;margin-right: 10px"><i class="icon-edit"></i> ${_('Edit')}</a>
-          <h4><i class="icon-list"></i> ${ collection.name }</h4>
+          <h4><i class="icon-list"></i> ${ collection.name } - ${ collection.is_core_only }</h4>
         </li>
       % endfor
       </ul>

+ 13 - 15
apps/search/src/search/templates/admin_collections_wizard.mako

@@ -27,7 +27,6 @@ ${ commonheader(_('Search'), "search", user) | n,unicode }
 <link rel="stylesheet" href="/search/static/css/admin.css">
 
 <div class="container-fluid">
-  % if collections:
   <h1>${_('Import a new collection')}</h1>
 
   <div class="row-fluid">
@@ -35,17 +34,19 @@ ${ commonheader(_('Search'), "search", user) | n,unicode }
       <ul id="collections">
       % for collection in collections:
         <li>
-          <a class="addCollection" data-name="${ collection }">
+          <a class="addCollection" data-name="${ collection }" data-type="collection">
             <h4><i class="icon-list"></i> ${ collection }</h4>
           </a>
         </li>
       % endfor
+      % if not collections:
+        ## TODO: maybe better to list them as disabled with imported icon etc
+        ${ _('All available collections from the Solr URL in hue.ini have been imported.') }      
+      % endif
       </ul>
     </div>
   </div>
-  % endif
 
-  % if cores:
   <h1>${_('Import a new core')}</h1>
 
   <div class="row-fluid">
@@ -53,21 +54,17 @@ ${ commonheader(_('Search'), "search", user) | n,unicode }
       <ul id="collections">
       % for core in cores:
         <li>
-          <h4><i class="icon-list"></i> ${ core }</h4>
+          <a class="addCollection" data-name="${ core }" data-type="core">
+            <h4><i class="icon-list"></i> ${ core }</h4>
+          </a>
         </li>
       % endfor
+      % if not cores:
+        ${ _('All available cores Solr URL in hue.ini have been imported.') }      
+      % endif      
       </ul>
     </div>
   </div>
-  % endif
-
-  % if not collections and not cores:
-  <h1>${_('No available indexes')}</h1>
-
-  <div class="row-fluid">
-    ${ _('All the available collections have been installed or you are pointing to a bad Solr URL in hue.ini.') }
-  </div>
-  % endif
 
 </div>
 
@@ -97,7 +94,8 @@ ${ commonheader(_('Search'), "search", user) | n,unicode }
   $(document).ready(function () {
     $(".addCollection").click(function() {
       var collectionName = $(this).data('name');
-      $.post('${ url("search:admin_collections_wizard") }', {type: 'collection', name: collectionName},
+      var collectionType = $(this).data('type');
+      $.post('${ url("search:admin_collections_wizard") }', {type: collectionType, name: collectionName},
         function(response) {
           if (response['status'] != 0) {
             $.jHueNotify.error("${ _('Problem: ') }" + response['message']);

+ 0 - 3
apps/search/src/search/urls.py

@@ -20,13 +20,10 @@ from django.conf.urls.defaults import patterns, url
 urlpatterns = patterns('search.views',
   url(r'^$', 'index', name='index'),
   url(r'^query$', 'index', name='query'),
-  url(r'^admin$', 'admin', name='admin'),
 
   url(r'^admin/collections_$', 'admin_collections', name='admin_collections'),
   url(r'^admin/collections_wizard$', 'admin_collections_wizard', name='admin_collections_wizard'),
 
-  #url(r'^admin/collections$', 'admin', name='admin_collections'),
-
   url(r'^admin/collection/(?P<collection>\w+)$', 'admin_collection_template', name='admin_collection'),
   url(r'^admin/collection/(?P<collection>\w+)/properties$', 'admin_collection_properties', name='admin_collection_properties'),
   url(r'^admin/collection/(?P<collection>\w+)/template$', 'admin_collection_template', name='admin_collection_template'),

+ 1 - 10
apps/search/src/search/views.py

@@ -126,15 +126,6 @@ def admin_collections_wizard(request):
     })
 
 
-@allow_admin_only
-def admin(request):
-  hue_collections = Collection.objects.all()
-
-  return render('admin.mako', request, {
-    'hue_collections': hue_collections,
-  })
-
-
 @allow_admin_only
 def admin_collection_properties(request, collection):  
   hue_collection = Collection.objects.get(name=collection)
@@ -160,7 +151,7 @@ def admin_collection_properties(request, collection):
 @allow_admin_only
 def admin_collection_template(request, collection):
   hue_collection = Collection.objects.get(name=collection)  
-  solr_collection = SolrApi(SOLR_URL.get()).collection(collection)  
+  solr_collection = SolrApi(SOLR_URL.get()).collection_or_core(hue_collection)  
 
   if request.method == 'POST':
     hue_collection.result.update_from_post(request.POST)