فهرست منبع

Merge pull request #4883 from weseek/feat/82389-highligh-page-path

Feat/82389 highligh page path
Yohei Shiina 4 سال پیش
والد
کامیت
6afe5d9dd7

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

@@ -3,7 +3,6 @@ import React, { FC } from 'react';
 import Clamp from 'react-multiline-clamp';
 import Clamp from 'react-multiline-clamp';
 
 
 import { UserPicture, PageListMeta, PagePathLabel } from '@growi/ui';
 import { UserPicture, PageListMeta, PagePathLabel } from '@growi/ui';
-import { DevidedPagePath } from '@growi/core';
 
 
 import { IPageSearchResultData } from '../../interfaces/search';
 import { IPageSearchResultData } from '../../interfaces/search';
 import PageItemControl from '../Common/Dropdown/PageItemControl';
 import PageItemControl from '../Common/Dropdown/PageItemControl';
@@ -28,13 +27,19 @@ const SearchResultListItem: FC<Props> = (props: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 = `#${pageData._id}`;
   const pageId = `#${pageData._id}`;
 
 
-  const isPathIncludedHtml = pageMeta.elasticSearchResult?.highlightedPath != null || pageData.path != null;
-  const dPagePath = new DevidedPagePath(pageData.path, false, true);
+  const pageTitle = (
+    <PagePathLabel
+      path={pageMeta.elasticSearchResult?.highlightedPath || pageData.path}
+      isLatterOnly
+      isPathIncludedHtml={pageMeta.elasticSearchResult?.isHtmlInPath}
+    >
+    </PagePathLabel>
+  );
   const pagePathElem = (
   const pagePathElem = (
     <PagePathLabel
     <PagePathLabel
       path={pageMeta.elasticSearchResult?.highlightedPath || pageData.path}
       path={pageMeta.elasticSearchResult?.highlightedPath || pageData.path}
       isFormerOnly
       isFormerOnly
-      isPathIncludedHtml={isPathIncludedHtml}
+      isPathIncludedHtml={pageMeta.elasticSearchResult?.isHtmlInPath}
     />
     />
   );
   );
 
 
@@ -70,7 +75,7 @@ const SearchResultListItem: FC<Props> = (props:Props) => {
               {/* page title */}
               {/* page title */}
               <h3 className="mb-0">
               <h3 className="mb-0">
                 <UserPicture user={pageData.lastUpdateUser} />
                 <UserPicture user={pageData.lastUpdateUser} />
-                <span className="mx-2 search-result-page-title">{dPagePath.latter}</span>
+                <span className="mx-2 search-result-page-title">{pageTitle}</span>
               </h3>
               </h3>
               {/* page meta */}
               {/* page meta */}
               <div className="d-flex mx-2">
               <div className="d-flex mx-2">

+ 8 - 7
packages/app/src/interfaces/search.ts

@@ -7,15 +7,16 @@ export enum CheckboxType {
 }
 }
 
 
 export type IPageSearchResultData = {
 export type IPageSearchResultData = {
-  pageData: IPageHasId,
+  pageData: IPageHasId;
   pageMeta: {
   pageMeta: {
-    bookmarkCount?: number,
+    bookmarkCount?: number;
     elasticSearchResult?: {
     elasticSearchResult?: {
-      snippet: string,
-      highlightedPath: string,
-    },
-  },
-}
+      snippet: string;
+      highlightedPath: string;
+      isHtmlInPath: boolean;
+    };
+  };
+};
 
 
 export const SORT_AXIS = {
 export const SORT_AXIS = {
   RELATION_SCORE: 'relationScore',
   RELATION_SCORE: 'relationScore',

+ 6 - 0
packages/app/src/server/service/search.ts

@@ -401,16 +401,22 @@ class SearchService implements SearchQueryParser, SearchResolver {
         pageData.lastUpdateUser = serializeUserSecurely(pageData.lastUpdateUser);
         pageData.lastUpdateUser = serializeUserSecurely(pageData.lastUpdateUser);
       }
       }
 
 
+      // const data = searchResult.data.find((data) => {
+      //   return pageData.id === data._id;
+      // });
+
       // increment elasticSearchResult
       // increment elasticSearchResult
       let elasticSearchResult;
       let elasticSearchResult;
       const highlightData = data._highlight;
       const highlightData = data._highlight;
       if (highlightData != null) {
       if (highlightData != null) {
         const snippet = highlightData['body.en'] || highlightData['body.ja'] || '';
         const snippet = highlightData['body.en'] || highlightData['body.ja'] || '';
         const pathMatch = highlightData['path.en'] || highlightData['path.ja'] || '';
         const pathMatch = highlightData['path.en'] || highlightData['path.ja'] || '';
+        const isHtmlInPath = highlightData['path.en'] != null || highlightData['path.ja'] != null;
 
 
         elasticSearchResult = {
         elasticSearchResult = {
           snippet: filterXss.process(snippet),
           snippet: filterXss.process(snippet),
           highlightedPath: filterXss.process(pathMatch),
           highlightedPath: filterXss.process(pathMatch),
+          isHtmlInPath,
         };
         };
       }
       }