yusuketk 7 лет назад
Родитель
Сommit
9465ff8ba4
2 измененных файлов с 6 добавлено и 1 удалено
  1. 3 0
      resource/search/mappings.json
  2. 3 1
      src/server/util/search.js

+ 3 - 0
resource/search/mappings.json

@@ -93,6 +93,9 @@
         "updated_at": {
           "type": "date",
           "format": "dateOptionalTime"
+        },
+        "tagIds": {
+          "type": "object"
         }
       }
     }

+ 3 - 1
src/server/util/search.js

@@ -280,6 +280,7 @@ SearchClient.prototype.addAllPages = async function() {
   const Page = this.crowi.model('Page');
   const allPageCount = await Page.allPageCount();
   const Bookmark = this.crowi.model('Bookmark');
+  const PageTagRelation = this.crowi.model('PageTagRelation');
   const cursor = Page.getStreamOfFindAll();
   let body = [];
   let sent = 0;
@@ -311,7 +312,8 @@ SearchClient.prototype.addAllPages = async function() {
         total++;
 
         const bookmarkCount = await Bookmark.countByPageId(doc._id);
-        const page = { ...doc, bookmarkCount };
+        const tagRelations = await PageTagRelation.find({ relatedPage: doc._id });
+        const page = { ...doc, bookmarkCount, tagIds: tagRelations.map((relation) => { return relation.relatedTag }) };
         self.prepareBodyForCreate(body, page);
 
         if (body.length >= 4000) {