SULLEY\ryo-h 4 tahun lalu
induk
melakukan
0519e7ce23

+ 0 - 2
packages/app/src/components/SearchPage/SearchResultList.jsx

@@ -9,12 +9,10 @@ class SearchResultList extends React.Component {
       // TODO : send cetain  length of body (revisionBody) from elastisearch by adding some settings to the query and
       //         when keyword is not in page content, display revisionBody.
       // TASK : https://estoc.weseek.co.jp/redmine/issues/79606
-      const snippet = page.elasticSearchResult.snippet;
       return (
         <SearchResultListItem
           page={page}
           onClickInvoked={this.props.onClickInvoked}
-          snippet={snippet}
           noLink
         />
       );

+ 5 - 3
packages/app/src/components/SearchPage/SearchResultListItem.tsx

@@ -13,14 +13,16 @@ type Props ={
     path: string,
     noLink: boolean,
     lastUpdateUser: any
+    elasticSearchResult: {
+      snippet: string,
+    }
   },
-  snippet: string,
   onClickInvoked: (data: string) => void,
 }
 
 const SearchResultListItem: FC<Props> = (props:Props) => {
 
-  const { page, snippet, onClickInvoked } = props;
+  const { page, onClickInvoked } = props;
 
   // Add prefix 'id_' in pageId, because scrollspy of bootstrap doesn't work when the first letter of id attr of target component is numeral.
   const pageId = `#${page._id}`;
@@ -87,7 +89,7 @@ const SearchResultListItem: FC<Props> = (props:Props) => {
 
             </div>
             {/* eslint-disable-next-line react/no-danger */}
-            <div className="mt-1" dangerouslySetInnerHTML={{ __html: snippet }}></div>
+            <div className="mt-1" dangerouslySetInnerHTML={{ __html: page.elasticSearchResult.snippet }}></div>
           </div>
         </div>
       </a>

+ 3 - 3
packages/app/src/server/service/search.js

@@ -165,13 +165,13 @@ class SearchService {
   formatResult(esResult) {
     esResult.data.forEach((data) => {
       const highlightData = data._highlight;
-      const snippet = highlightData['body.en'] || highlightData['body.ja'];
-      const pathMatch = highlightData['path.en'] || highlightData['path.ja'];
+      const snippet = highlightData['body.en'] || highlightData['body.ja'] || '';
+      const pathMatch = highlightData['path.en'] || highlightData['path.ja'] || '';
 
       data.elasticSearchResult = {
         snippet: filterXss.process(snippet),
         // todo: use filter xss.process() for matchedPath;
-        matchedPath: pathMatch || '',
+        matchedPath: pathMatch,
       };
     });
     return esResult;