소스 검색

[search] Guess id field for result highlighting

Romain Rigaux 11 년 전
부모
커밋
eb46c8e65c
2개의 변경된 파일7개의 추가작업 그리고 8개의 파일을 삭제
  1. 6 7
      apps/search/src/search/models.py
  2. 1 1
      apps/search/src/search/templates/search2.mako

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

@@ -250,7 +250,6 @@ class Collection(models.Model):
 
   def get_c(self, user):
     props = self.properties_dict
-    print props
     if 'collection' not in props:
       props['collection'] = self.get_default(user)
     
@@ -258,9 +257,9 @@ class Collection(models.Model):
 
   def get_default(self, user):      
     fields = self.fields_data(user)
-    id_field = [field.name for field in fields if field.get('isId')]
-    if not id_field:
-      id_field = 'id'
+    id_field = [field['name'] for field in fields if field.get('isId')]
+    if id_field:
+      id_field = id_field[0]
     fields = [field.get('name') for field in self.fields_data(user)]
   
     TEMPLATE = {
@@ -299,7 +298,7 @@ class Collection(models.Model):
     schema_fields = schema_fields['schema']['fields']
 
     return sorted([{'name': str(field), 'type': str(attributes.get('type', '')),
-                    'isId': attributes.get('stored') and attributes.get('required') and attributes.get('multiValued')
+                    'isId': attributes.get('required') and attributes.get('uniqueKey')
                   }
                   for field, attributes in schema_fields.iteritems()])
 
@@ -441,7 +440,7 @@ def augment_solr_response2(response, collection, solr_query):
 
   # TODO HTML escape docs!
   
-  highlighted_fields = response.get('highlighting', [])
+  highlighted_fields = response.get('highlighting', {}).keys()
   if highlighted_fields:
     id_field = collection.get('idField')    
     if id_field:
@@ -449,7 +448,7 @@ def augment_solr_response2(response, collection, solr_query):
         if id_field in doc and doc[id_field] in highlighted_fields:
           doc.update(response['highlighting'][doc[id_field]])
     else:
-      response['warning'] = _("The Solr schema requires an 'id' field for performing the result highlighting")
+      response['warning'] = _("The Solr schema requires an id field for performing the result highlighting")
       
         
   response['total_pages'] = int(math.ceil((float(response['response']['numFound']) / float(solr_query['rows']))))

+ 1 - 1
apps/search/src/search/templates/search2.mako

@@ -165,7 +165,7 @@ ${ commonheader(_('Search'), "search", user, "90px") | n,unicode }
   <div style="float: left; margin-left: 20px" data-bind="visible: columns().length > 0">
     <div style="font-weight: bold; color: #999; padding-left: 8px">${_('WIDGETS')}</div>
     <div class="draggable-widget" data-bind="draggable: draggableResultset" title="${_('Results')}" rel="tooltip" data-placement="top"><a href="#"><i class="fa fa-table"></i></a></div>    
-    <div class="draggable-widget" data-bind="draggable: draggableFacet" title="${_('Text Facet')}" rel="tooltip" data-placement="top"><a href="#"><i class="fa fa-sort-amount-desc"></i></a></div>    
+    <div class="draggable-widget" data-bind="draggable: draggableFacet" title="${_('Text Facet')}" rel="tooltip" data-placement="top"><a href="#"><i class="fa fa-sort-amount-asc"></i></a></div>    
     <div class="draggable-widget" data-bind="draggable: draggableBar" title="${_('Timeline')}" rel="tooltip" data-placement="top"><a href="#"><i class="hcha hcha-bar-chart"></i></a></div>
     <div class="draggable-widget" data-bind="draggable: draggableArea" title="${_('Area Chart')}" rel="tooltip" data-placement="top"><a href="#"><i class="hcha hcha-area-chart"></i></a></div>
     <div class="draggable-widget" data-bind="draggable: draggablePie" title="${_('Pie Chart')}" rel="tooltip" data-placement="top"><a href="#"><i class="hcha hcha-pie-chart"></i></a></div>