Procházet zdrojové kódy

Merge branch 'feat/77515-78577-show-snippet-in-search-result' into feat/77515-79940-highlight-page-path

# Conflicts:
#	packages/app/src/components/SearchPage/SearchResultList.jsx
#	packages/app/src/components/SearchPage/SearchResultListItem.tsx
#	packages/app/src/server/service/search.js
SULLEY\ryo-h před 4 roky
rodič
revize
a0b327c933

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

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

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

@@ -13,17 +13,17 @@ type Props ={
     path: string,
     path: string,
     noLink: boolean,
     noLink: boolean,
     lastUpdateUser: any
     lastUpdateUser: any
+    elasticSearchResult: {
+      snippet: string,
+    }
   },
   },
-  snippet: string,
   highlightedPath: string,
   highlightedPath: string,
   onClickInvoked: (data: string) => void,
   onClickInvoked: (data: string) => void,
 }
 }
 
 
 const SearchResultListItem: FC<Props> = (props:Props) => {
 const SearchResultListItem: FC<Props> = (props:Props) => {
 
 
-  const {
-    page, snippet, highlightedPath, 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.
   // 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}`;
   const pageId = `#${page._id}`;
@@ -91,7 +91,7 @@ const SearchResultListItem: FC<Props> = (props:Props) => {
 
 
             </div>
             </div>
             {/* eslint-disable-next-line react/no-danger */}
             {/* 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>
         </div>
         </div>
       </a>
       </a>

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

@@ -165,8 +165,8 @@ class SearchService {
   formatResult(esResult) {
   formatResult(esResult) {
     esResult.data.forEach((data) => {
     esResult.data.forEach((data) => {
       const highlightData = data._highlight;
       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 = {
       data.elasticSearchResult = {
         snippet: filterXss.process(snippet),
         snippet: filterXss.process(snippet),