فهرست منبع

[search] Empty query matches all the fields

Make it configurable too
Romain Rigaux 12 سال پیش
والد
کامیت
da0b3da08e

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

@@ -26,6 +26,7 @@ import logging
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.rest.http_client import HttpClient, RestException
 from desktop.lib.rest.http_client import HttpClient, RestException
 from desktop.lib.rest.resource import Resource
 from desktop.lib.rest.resource import Resource
+from search.conf import EMPTY_QUERY
 
 
 
 
 LOG = logging.getLogger(__name__)
 LOG = logging.getLogger(__name__)
@@ -43,7 +44,7 @@ class SolrApi(object):
   def query(self, solr_query, hue_core):
   def query(self, solr_query, hue_core):
     try:
     try:
       params = (
       params = (
-          ('q', solr_query['q'] or '*'),
+          ('q', solr_query['q'] or EMPTY_QUERY.get()),
           ('wt', 'json'),
           ('wt', 'json'),
           ('rows', solr_query['rows']),
           ('rows', solr_query['rows']),
           ('start', solr_query['start']),
           ('start', solr_query['start']),

+ 6 - 0
apps/search/src/search/conf.py

@@ -39,3 +39,9 @@ SOLR_URL = Config(
 
 
 # ZOOKEEPER URL
 # ZOOKEEPER URL
 # for COLLECTIONS
 # for COLLECTIONS
+
+
+EMPTY_QUERY = Config(
+  key="empty_query",
+  help=_("Query sent when no term is entered."),
+  default="*:*")

+ 2 - 2
apps/search/src/search/search_controller.py

@@ -44,7 +44,7 @@ class SearchController(object):
     try:
     try:
       solr_collections = SolrApi(SOLR_URL.get()).collections()
       solr_collections = SolrApi(SOLR_URL.get()).collections()
       for name in Collection.objects.values_list('name', flat=True):
       for name in Collection.objects.values_list('name', flat=True):
-        solr_collections.pop(name, None)      
+        solr_collections.pop(name, None)
     except Exception, e:
     except Exception, e:
       LOG.warn('No Zookeeper servlet running on Solr server: %s' % e)
       LOG.warn('No Zookeeper servlet running on Solr server: %s' % e)
       solr_collections = []
       solr_collections = []
@@ -74,6 +74,6 @@ class SearchController(object):
       core = cores[attrs['name']]
       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)
       hue_collection, created = Collection.objects.get_or_create(name=attrs['name'], solr_properties=core, is_enabled=True, is_core_only=True)
-      return hue_collection      
+      return hue_collection
     else:
     else:
       raise PopupException(_('Collection type does not exit: %s') % attrs)
       raise PopupException(_('Collection type does not exit: %s') % attrs)

+ 8 - 8
apps/search/src/search/templates/admin_collection_properties_solr_properties.mako

@@ -30,7 +30,7 @@
   % else:
   % else:
     % for key, value in solr_collection.iteritems():
     % for key, value in solr_collection.iteritems():
       ${ key } : ${ value }
       ${ key } : ${ value }
-    % endfor  
+    % endfor
   % endif
   % endif
 </%def>
 </%def>
 
 
@@ -42,7 +42,7 @@
   % else:
   % else:
     % for key, value in solr_collection.iteritems():
     % for key, value in solr_collection.iteritems():
       ${ key } : ${ value }
       ${ key } : ${ value }
-    % endfor  
+    % endfor
   % endif
   % endif
 </%def>
 </%def>
 
 
@@ -51,9 +51,9 @@
   </%def>
   </%def>
 
 
   <%def name="content()">
   <%def name="content()">
-  
+
   % if not hue_collection.is_core_only:
   % if not hue_collection.is_core_only:
-    <div class="tab-content">         
+    <div class="tab-content">
       <div class="tab-pane active" id="index_properties">
       <div class="tab-pane active" id="index_properties">
         <table class="table">
         <table class="table">
           <thead>
           <thead>
@@ -67,7 +67,7 @@
             % for key, value in solr_collection.iteritems():
             % for key, value in solr_collection.iteritems():
               <td>${ key }</td>
               <td>${ key }</td>
               <td>${ value }</td>
               <td>${ value }</td>
-            % endfor          
+            % endfor
           </tr>
           </tr>
           </tbody>
           </tbody>
         </table>
         </table>
@@ -79,7 +79,7 @@
       <li><a href="#collection_properties" data-toggle="tab">${_('Collection properties')}</a></li>
       <li><a href="#collection_properties" data-toggle="tab">${_('Collection properties')}</a></li>
     </ul>
     </ul>
 
 
-    <div class="tab-content">         
+    <div class="tab-content">
       <div class="tab-pane active" id="index_properties">
       <div class="tab-pane active" id="index_properties">
         <table class="table">
         <table class="table">
           <thead>
           <thead>
@@ -93,7 +93,7 @@
             % for key, value in solr_collection.iteritems():
             % for key, value in solr_collection.iteritems():
               <td>${ key }</td>
               <td>${ key }</td>
               <td>${ value }</td>
               <td>${ value }</td>
-            % endfor          
+            % endfor
           </tr>
           </tr>
           </tbody>
           </tbody>
         </table>
         </table>
@@ -111,7 +111,7 @@
             % for key, value in solr_collection.iteritems():
             % for key, value in solr_collection.iteritems():
               <td>${ key }</td>
               <td>${ key }</td>
               <td>${ value }</td>
               <td>${ value }</td>
-            % endfor          
+            % endfor
           </tr>
           </tr>
           </tbody>
           </tbody>
         </table>
         </table>

+ 3 - 3
apps/search/src/search/views.py

@@ -167,7 +167,7 @@ def admin_collections_import(request):
 
 
 
 
 @allow_admin_only
 @allow_admin_only
-def admin_collection_properties(request, collection):  
+def admin_collection_properties(request, collection):
   hue_collection = Collection.objects.get(name=collection)
   hue_collection = Collection.objects.get(name=collection)
   solr_collection = SolrApi(SOLR_URL.get()).collection_or_core(hue_collection)
   solr_collection = SolrApi(SOLR_URL.get()).collection_or_core(hue_collection)
 
 
@@ -190,8 +190,8 @@ def admin_collection_properties(request, collection):
 
 
 @allow_admin_only
 @allow_admin_only
 def admin_collection_template(request, collection):
 def admin_collection_template(request, collection):
-  hue_collection = Collection.objects.get(name=collection)  
-  solr_collection = SolrApi(SOLR_URL.get()).collection_or_core(hue_collection)  
+  hue_collection = Collection.objects.get(name=collection)
+  solr_collection = SolrApi(SOLR_URL.get()).collection_or_core(hue_collection)
 
 
   if request.method == 'POST':
   if request.method == 'POST':
     hue_collection.result.update_from_post(request.POST)
     hue_collection.result.update_from_post(request.POST)