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

added contentWithNoKeyword to page

Mao 4 лет назад
Родитель
Сommit
ea133039ed

+ 6 - 1
packages/app/src/components/SearchPage/SearchResultList.jsx

@@ -12,7 +12,12 @@ class SearchResultList extends React.Component {
       // TODO : send cetain chars of body (revisionBody) from elastisearch by adding some settings to the query
       // TODO : send cetain chars of body (revisionBody) from elastisearch by adding some settings to the query
       // story: 77515 task : not created yet.
       // story: 77515 task : not created yet.
       let snippet = '';
       let snippet = '';
-      if (page.elasticSearchResultInfo.snippet.length > 40) { snippet = page.elasticSearchResultInfo.snippet.substr(0, 40) }
+      if (page.elasticSearchResultInfo.contentWithNoSearchedKeyword != null) {
+        if (page.elasticSearchResultInfo.contentWithNoSearchedKeyword.length > 40) {
+          snippet = page.elasticSearchResultInfo.contentWithNoSearchedKeyword.substr(0, 40);
+        }
+        snippet = page.elasticSearchResultInfo.contentWithNoSearchedKeyword;
+      }
       else { snippet = page.elasticSearchResultInfo.snippet }
       else { snippet = page.elasticSearchResultInfo.snippet }
       return (
       return (
         <li key={page._id} className="nav-item page-list-li w-100 m-0 border-bottom">
         <li key={page._id} className="nav-item page-list-li w-100 m-0 border-bottom">

+ 2 - 1
packages/app/src/server/routes/search.js

@@ -164,7 +164,7 @@ module.exports = function(crowi, app) {
         const data = esResult.data.find((data) => { return page.id === data._id });
         const data = esResult.data.find((data) => { return page.id === data._id });
         page._doc.tags = data._source.tag_names;
         page._doc.tags = data._source.tag_names;
         if (data._highlight['body.en'] == null && data._highlight['body.ja'] == null) {
         if (data._highlight['body.en'] == null && data._highlight['body.ja'] == null) {
-          elasticSearchResult.snippet = myXss.process(data._source.body);
+          elasticSearchResult.contentWithNoSearchedKeyword = myXss.process(data._source.body);
         }
         }
         else {
         else {
           const snippet = data._highlight['body.en'] == null ? data._highlight['body.ja'] : data._highlight['body.en'];
           const snippet = data._highlight['body.en'] == null ? data._highlight['body.ja'] : data._highlight['body.en'];
@@ -196,6 +196,7 @@ module.exports = function(crowi, app) {
     catch (err) {
     catch (err) {
       return res.json(ApiResponse.error(err));
       return res.json(ApiResponse.error(err));
     }
     }
+    console.log(JSON.stringify(result));
     return res.json(ApiResponse.success(result));
     return res.json(ApiResponse.success(result));
   };
   };