|
|
@@ -138,8 +138,15 @@ class SearchService {
|
|
|
}
|
|
|
|
|
|
async searchKeyword(keyword, user, userGroups, searchOpts) {
|
|
|
+ const options = {
|
|
|
+ whiteList: {
|
|
|
+ em: ['class'],
|
|
|
+ },
|
|
|
+ };
|
|
|
+ const myXss = new xss.FilterXSS(options);
|
|
|
+ let esResult;
|
|
|
try {
|
|
|
- return await this.delegator.searchKeyword(keyword, user, userGroups, searchOpts);
|
|
|
+ esResult = await this.delegator.searchKeyword(keyword, user, userGroups, searchOpts);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -148,22 +155,8 @@ class SearchService {
|
|
|
this.isErrorOccuredOnSearching = true;
|
|
|
throw err;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- addElasticSearchInfo(pages, esResult) {
|
|
|
- const options = {
|
|
|
- whiteList: {
|
|
|
- em: ['class'],
|
|
|
- },
|
|
|
- };
|
|
|
- const myXss = new xss.FilterXSS(options);
|
|
|
-
|
|
|
- pages.map((page) => {
|
|
|
+ esResult.data.forEach((data) => {
|
|
|
const elasticSearchResult = { snippet: '', matchedPath: '' };
|
|
|
- const data = esResult.data.find((data) => {
|
|
|
- return page.id === data._id;
|
|
|
- });
|
|
|
- page._doc.tags = data._source.tag_names;
|
|
|
if (data._highlight['body.en'] == null && data._highlight['body.ja'] == null) {
|
|
|
elasticSearchResult.contentWithNoSearchedKeyword = myXss.process(data._source.body);
|
|
|
}
|
|
|
@@ -175,9 +168,9 @@ class SearchService {
|
|
|
const pathMatch = data._highlight['path.en'] == null ? data._highlight['path.ja'] : data._highlight['path.en'];
|
|
|
elasticSearchResult.matchedPath = pathMatch;
|
|
|
}
|
|
|
- page._doc.elasticSearchResultInfo = elasticSearchResult;
|
|
|
- return page;
|
|
|
+ data.elasticSearchResultInfo = elasticSearchResult;
|
|
|
});
|
|
|
+ return esResult;
|
|
|
}
|
|
|
|
|
|
}
|