Просмотр исходного кода

return result pages with tag data when search page

yusuketk 7 лет назад
Родитель
Сommit
5ef2496f44
2 измененных файлов с 7 добавлено и 2 удалено
  1. 5 0
      src/server/models/page.js
  2. 2 2
      src/server/util/search.js

+ 5 - 0
src/server/models/page.js

@@ -764,6 +764,11 @@ module.exports = function(crowi) {
     // find
     builder.populateDataToList(User.USER_PUBLIC_FIELDS, User.IMAGE_POPULATION);
     const pages = await builder.query.exec('find');
+    pages.map((page) => {
+      const result = ids.find((data) => { return page.id === data._id });
+      page.tags = result._source.tag_names;
+      return page;
+    });
 
     const result = {
       pages, totalCount, offset: opt.offset, limit: opt.limit,

+ 2 - 2
src/server/util/search.js

@@ -387,7 +387,7 @@ SearchClient.prototype.search = async function(query) {
 
 SearchClient.prototype.createSearchQuerySortedByUpdatedAt = function(option) {
   // getting path by default is almost for debug
-  let fields = ['path', 'bookmark_count'];
+  let fields = ['path', 'bookmark_count', 'tag_names'];
   if (option) {
     fields = option.fields || fields;
   }
@@ -408,7 +408,7 @@ SearchClient.prototype.createSearchQuerySortedByUpdatedAt = function(option) {
 };
 
 SearchClient.prototype.createSearchQuerySortedByScore = function(option) {
-  let fields = ['path', 'bookmark_count'];
+  let fields = ['path', 'bookmark_count', 'tag_names'];
   if (option) {
     fields = option.fields || fields;
   }