visuddhinanda 3 лет назад
Родитель
Сommit
963b3c416e

+ 3 - 1
dashboard/src/components/fts/FtsBookList.tsx

@@ -35,6 +35,7 @@ interface IWidget {
   para?: number;
   match?: string | null;
   keyWord2?: string;
+  view?: string;
   onSelect?: Function;
 }
 
@@ -46,13 +47,14 @@ const Widget = ({
   para,
   keyWord2,
   match,
+  view = "pali",
   onSelect,
 }: IWidget) => {
   const [ftsData, setFtsData] = useState<IFtsItem[]>();
   const [total, setTotal] = useState<number>();
 
   useEffect(() => {
-    let url = `/v2/search-book-list?key=${keyWord}`;
+    let url = `/v2/search-book-list?view=${view}&key=${keyWord}`;
     if (typeof tags !== "undefined") {
       url += `&tags=${tags}`;
     }

+ 28 - 3
dashboard/src/components/fts/FullSearchInput.tsx

@@ -1,9 +1,10 @@
-import { AutoComplete, Badge, Input, Typography } from "antd";
+import { AutoComplete, Badge, Input, Select, Space, Typography } from "antd";
 import { SizeType } from "antd/lib/config-provider/SizeContext";
 import { useState } from "react";
 import { get } from "../../request";
 
 const { Text } = Typography;
+const { Option } = Select;
 
 export interface IWordIndexData {
   word: string;
@@ -31,8 +32,10 @@ interface IWidget {
   para?: number;
   size?: SizeType;
   width?: string | number;
+  searchPage?: boolean;
   onSearch?: Function;
   onSplit?: Function;
+  onPageTypeChange?: Function;
 }
 const Widget = ({
   value,
@@ -41,6 +44,8 @@ const Widget = ({
   size = "middle",
   width,
   onSearch,
+  searchPage = false,
+  onPageTypeChange,
 }: IWidget) => {
   const [options, setOptions] = useState<ValueType[]>([]);
   const [input, setInput] = useState<string | undefined>(value);
@@ -76,8 +81,28 @@ const Widget = ({
       setOptions(words);
     });
   };
+
+  const selectBefore = (
+    <Select
+      defaultValue="P"
+      size="large"
+      style={{ width: 120 }}
+      onChange={(value: string) => {
+        if (typeof onPageTypeChange !== "undefined") {
+          onPageTypeChange(value);
+        }
+      }}
+    >
+      <Option value="P">PTS</Option>
+      <Option value="M">Myanmar</Option>
+      <Option value="T">Thai</Option>
+      <Option value="V">VRI</Option>
+      <Option value="O">Other</Option>
+    </Select>
+  );
   return (
-    <>
+    <Space>
+      {searchPage ? selectBefore : undefined}
       <AutoComplete
         style={{ width: width }}
         value={input}
@@ -131,7 +156,7 @@ const Widget = ({
           }}
         />
       </AutoComplete>
-    </>
+    </Space>
   );
 };
 

+ 15 - 6
dashboard/src/components/fts/FullTextSearchResult.tsx

@@ -10,11 +10,11 @@ import "./search.css";
 const { Title, Text } = Typography;
 
 interface IFtsData {
-  rank: number;
-  highlight: string;
+  rank?: number;
+  highlight?: string;
   book: number;
   paragraph: number;
-  content: string;
+  content?: string;
   title?: string;
   paliTitle?: string;
   path?: ITocPathNode[];
@@ -44,6 +44,8 @@ interface IWidget {
   orderBy?: string | null;
   match?: string | null;
   keyWord2?: string;
+  view?: string;
+  pageType?: string;
 }
 const Widget = ({
   keyWord,
@@ -54,6 +56,8 @@ const Widget = ({
   orderBy,
   match,
   keyWord2,
+  view = "pali",
+  pageType,
 }: IWidget) => {
   const [ftsData, setFtsData] = useState<IFtsItem[]>();
 
@@ -61,7 +65,7 @@ const Widget = ({
   const [currPage, setCurrPage] = useState<number>(1);
 
   useEffect(() => {
-    let url = `/v2/search?key=${keyWord}`;
+    let url = `/v2/search?view=${view}&key=${keyWord}`;
     if (typeof tags !== "undefined") {
       url += `&tags=${tags}`;
     }
@@ -74,6 +78,9 @@ const Widget = ({
     if (match) {
       url += `&match=${match}`;
     }
+    if (pageType) {
+      url += `&type=${pageType}`;
+    }
     const offset = (currPage - 1) * 10;
     url += `&limit=10&offset=${offset}`;
     console.log("fetch url", url);
@@ -85,7 +92,9 @@ const Widget = ({
             paragraph: item.paragraph,
             title: item.title ? item.title : item.paliTitle,
             paliTitle: item.paliTitle,
-            content: item.highlight.replaceAll("** ti ", "**ti "),
+            content: item.highlight
+              ? item.highlight.replaceAll("** ti ", "**ti ")
+              : item.content,
             path: item.path,
           };
         });
@@ -93,7 +102,7 @@ const Widget = ({
         setTotal(json.data.count);
       }
     });
-  }, [bookId, currPage, keyWord, match, orderBy, tags]);
+  }, [bookId, currPage, keyWord, match, orderBy, pageType, tags, view]);
   return (
     <List
       itemLayout="vertical"

+ 46 - 1
dashboard/src/pages/library/search/search.tsx

@@ -1,6 +1,6 @@
 import { useNavigate, useParams, useSearchParams } from "react-router-dom";
 import { useEffect, useState } from "react";
-import { Row, Col, Breadcrumb, Space } from "antd";
+import { Row, Col, Breadcrumb, Space, Tabs } from "antd";
 import FullSearchInput from "../../../components/fts/FullSearchInput";
 import BookTree from "../../../components/corpus/BookTree";
 import FullTextSearchResult from "../../../components/fts/FullTextSearchResult";
@@ -12,7 +12,10 @@ const Widget = () => {
   const [searchParams, setSearchParams] = useSearchParams();
   const [bookRoot, setBookRoot] = useState("default");
   const [bookPath, setBookPath] = useState<string[]>([]);
+  const [searchPage, setSearchPage] = useState(false);
   const navigate = useNavigate();
+  const [pageType, setPageType] = useState("P");
+  const [view, setView] = useState("pali");
 
   useEffect(() => {}, [key, searchParams]);
 
@@ -56,10 +59,14 @@ const Widget = () => {
                     size="large"
                     width={"500px"}
                     value={key}
+                    searchPage={searchPage}
                     tags={searchParams.get("tags")?.split(",")}
                     onSearch={(value: string) => {
                       navigate(`/search/key/${value}`);
                     }}
+                    onPageTypeChange={(value: string) => {
+                      setPageType(value);
+                    }}
                   />
                   <FtsSetting
                     trigger="高级"
@@ -79,7 +86,44 @@ const Widget = () => {
                     <Breadcrumb.Item key={id}>{item}</Breadcrumb.Item>
                   ))}
                 </Breadcrumb>
+                <Tabs
+                  onChange={(activeKey: string) => {
+                    setView(activeKey);
+                    searchParams.set(view, activeKey);
+                    setSearchParams(searchParams);
+                    switch (activeKey) {
+                      case "pali":
+                        setSearchPage(false);
+                        break;
+                      case "page":
+                        setSearchPage(true);
+                        break;
+                      default:
+                        break;
+                    }
+                  }}
+                  size="small"
+                  items={[
+                    {
+                      label: `巴利原文`,
+                      key: "pali",
+                      children: <></>,
+                    },
+                    {
+                      label: `标题`,
+                      key: "title",
+                      children: <div></div>,
+                    },
+                    {
+                      label: `页码`,
+                      key: "page",
+                      children: <></>,
+                    },
+                  ]}
+                />
                 <FullTextSearchResult
+                  view={view}
+                  pageType={pageType}
                   keyWord={key}
                   tags={searchParams.get("tags")?.split(",")}
                   bookId={searchParams.get("book")}
@@ -90,6 +134,7 @@ const Widget = () => {
             </Col>
             <Col xs={0} sm={0} md={5}>
               <FtsBookList
+                view={view}
                 keyWord={key}
                 tags={searchParams.get("tags")?.split(",")}
                 match={searchParams.get("match")}