2
0
Эх сурвалжийг харах

add tagIds field in index

yusuketk 7 жил өмнө
parent
commit
9465ff8ba4

+ 3 - 0
resource/search/mappings.json

@@ -93,6 +93,9 @@
         "updated_at": {
         "updated_at": {
           "type": "date",
           "type": "date",
           "format": "dateOptionalTime"
           "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 Page = this.crowi.model('Page');
   const allPageCount = await Page.allPageCount();
   const allPageCount = await Page.allPageCount();
   const Bookmark = this.crowi.model('Bookmark');
   const Bookmark = this.crowi.model('Bookmark');
+  const PageTagRelation = this.crowi.model('PageTagRelation');
   const cursor = Page.getStreamOfFindAll();
   const cursor = Page.getStreamOfFindAll();
   let body = [];
   let body = [];
   let sent = 0;
   let sent = 0;
@@ -311,7 +312,8 @@ SearchClient.prototype.addAllPages = async function() {
         total++;
         total++;
 
 
         const bookmarkCount = await Bookmark.countByPageId(doc._id);
         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);
         self.prepareBodyForCreate(body, page);
 
 
         if (body.length >= 4000) {
         if (body.length >= 4000) {