Browse Source

fix search page errors

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 1 year ago
parent
commit
85890c13bc
2 changed files with 10 additions and 3 deletions
  1. 1 0
      client/src/pages/search/Styles.ts
  2. 9 3
      client/src/pages/search/VectorSearch.tsx

+ 1 - 0
client/src/pages/search/Styles.ts

@@ -67,6 +67,7 @@ export const getVectorSearchStyles = makeStyles((theme: Theme) => ({
     flexDirection: 'column',
     flexDirection: 'column',
     flexGrow: 0,
     flexGrow: 0,
     width: `calc(100% - 396px)`,
     width: `calc(100% - 396px)`,
+    height: `calc(100vh - 108px)`,
     padding: theme.spacing(1, 2),
     padding: theme.spacing(1, 2),
   },
   },
   toolbar: {
   toolbar: {

+ 9 - 3
client/src/pages/search/VectorSearch.tsx

@@ -1,5 +1,5 @@
 import { useCallback, useEffect, useMemo, useState, useContext } from 'react';
 import { useCallback, useEffect, useMemo, useState, useContext } from 'react';
-import { Typography, Button, Card, CardContent } from '@material-ui/core';
+import { Typography, CardContent } from '@material-ui/core';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
 import { useLocation } from 'react-router-dom';
 import { useLocation } from 'react-router-dom';
 import { ALL_ROUTER_TYPES } from '@/router/Types';
 import { ALL_ROUTER_TYPES } from '@/router/Types';
@@ -92,7 +92,7 @@ const VectorSearch = () => {
       return [];
       return [];
     }
     }
 
 
-    const fields = s.schema.fields || [];
+    const fields = (s.schema && s.schema.fields) || [];
 
 
     // vector field can't be output fields
     // vector field can't be output fields
     const invalidTypes = ['BinaryVector', 'FloatVector'];
     const invalidTypes = ['BinaryVector', 'FloatVector'];
@@ -236,7 +236,10 @@ const VectorSearch = () => {
       const col = collections.find(c => c.collection_name === collectionName);
       const col = collections.find(c => c.collection_name === collectionName);
 
 
       // only vector type fields can be select
       // only vector type fields can be select
-      const fieldOptions = getVectorFieldOptions(col?.schema.vectorFields!);
+      const fieldOptions =
+        col && col.schema
+          ? getVectorFieldOptions(col?.schema.vectorFields!)
+          : [];
       setFieldOptions(fieldOptions);
       setFieldOptions(fieldOptions);
       if (fieldOptions.length > 0) {
       if (fieldOptions.length > 0) {
         // set first option value as default field value
         // set first option value as default field value
@@ -379,6 +382,9 @@ const VectorSearch = () => {
                 // every time selected collection changed, reset field
                 // every time selected collection changed, reset field
                 setSelectedField('');
                 setSelectedField('');
                 setSearchResult([]);
                 setSearchResult([]);
+                // update location search
+                const search = `/#/search?collectionName=${collection}`;
+                window.history.pushState({}, '', search);
               }}
               }}
             />
             />
             <CustomSelector
             <CustomSelector