浏览代码

[search] Support fetching a document when searching by id

Doing a search with
id:6ddf6e38-7b83-423c-8873-39842dca2dbb
would do a request for
id <em>6ddf6e38-7b83-423c-8873-39842dca2dbb</em>
as we highlight the id.
Romain Rigaux 10 年之前
父节点
当前提交
ccc1f90
共有 2 个文件被更改,包括 6 次插入2 次删除
  1. 2 0
      apps/search/src/search/models.py
  2. 4 2
      apps/search/src/search/static/search/js/search.ko.js

+ 2 - 0
apps/search/src/search/models.py

@@ -805,6 +805,7 @@ def augment_solr_response(response, collection, query):
 
   # HTML escaping
   if not query.get('download'):
+    id_field = collection.get('idField', '')
     for doc in response['response']['docs']:
       for field, value in doc.iteritems():
         if isinstance(value, numbers.Number):
@@ -823,6 +824,7 @@ def augment_solr_response(response, collection, query):
 
       doc['externalLink'] = link
       doc['details'] = []
+      doc['hueId'] = doc.get(id_field, '')
 
   highlighted_fields = response.get('highlighting', {}).keys()
   if highlighted_fields and not query.get('download'):

+ 4 - 2
apps/search/src/search/static/search/js/search.ko.js

@@ -1421,8 +1421,10 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
                 var row = [];
                 var _externalLink = item.externalLink;
                 var _details = item.details;
+                var _id = item.hueId;
                 delete item["externalLink"];
                 delete item["details"];
+                delete item["hueId"];
                 var fields = self.collection.template.fieldsSelected();
                 // Display selected fields or whole json document
                 if (fields.length != 0) {
@@ -1440,7 +1442,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
                   }
                 }
                 var doc = {
-                  'id': item[self.collection.idField()],
+                  'id': _id,
                   'row': row,
                   'item': ko.mapping.fromJS(item),
                   'showEdit': ko.observable(false),
@@ -1451,7 +1453,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
                   'showDetails': ko.observable(false),
                   'leafletmap': leafletmap
                 };
-                if (!self.collection.template.isGridLayout()) {
+                if (! self.collection.template.isGridLayout()) {
                   // fix the fields that contain dots in the name
                   addTemplateFunctions(item);
                   if (self.additionalMustache != null && typeof self.additionalMustache == "function"){