Browse Source

fix: analyzer display error (#867)

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 2 months ago
parent
commit
563563ac93

+ 1 - 1
client/src/pages/databases/collections/schema/Schema.tsx

@@ -87,7 +87,7 @@ const Overview = () => {
                 label={collectionTrans('enableMatch')}
               />
             ) : null}
-            {findKeyValue(f.type_params, 'enable_analyzer') ? (
+            {findKeyValue(f.type_params, 'enable_analyzer') === 'true' ? (
               <Tooltip
                 title={findKeyValue(f.type_params, 'analyzer_params') as string}
                 arrow

+ 7 - 13
client/src/pages/dialogs/create/AnalyzerCheckboxField.tsx

@@ -5,7 +5,6 @@ import CustomSelector from '@/components/customSelector/CustomSelector';
 import CustomIconButton from '@/components/customButton/CustomIconButton';
 import icons from '@/components/icons/Icons';
 import { ANALYZER_OPTIONS } from './Constants';
-import { DataTypeEnum } from '@/consts';
 import { getAnalyzerParams } from '@/utils';
 import { rootContext } from '@/context';
 import EditJSONDialog from '@/pages/dialogs/EditJSONDialog';
@@ -45,8 +44,10 @@ const AnalyzerCheckboxField: FC<AnalyzerCheckboxFieldProps> = ({
   };
 
   const handleCheckboxChange = () => {
+    const isAnalyzerEnabled = !field.enable_analyzer;
     onChange(field.id!, {
-      enable_analyzer: !field.enable_analyzer,
+      enable_analyzer: isAnalyzerEnabled,
+      analyzer_params: isAnalyzerEnabled ? 'standard' : undefined,
     });
   };
 
@@ -96,13 +97,10 @@ const AnalyzerCheckboxField: FC<AnalyzerCheckboxFieldProps> = ({
       }}
     >
       <Checkbox
-        checked={
-          !!field.enable_analyzer ||
-          field.data_type === DataTypeEnum.VarCharBM25
-        }
+        checked={!!field.enable_analyzer}
         size="small"
         onChange={handleCheckboxChange}
-        disabled={field.data_type === DataTypeEnum.VarCharBM25}
+        disabled={false}
         style={{ padding: '8px' }}
       />
       <CustomSelector
@@ -110,17 +108,13 @@ const AnalyzerCheckboxField: FC<AnalyzerCheckboxFieldProps> = ({
         options={ANALYZER_OPTIONS}
         size="small"
         onChange={e => handleAnalyzerChange(e.target.value as string)}
-        disabled={
-          !field.enable_analyzer && field.data_type !== DataTypeEnum.VarCharBM25
-        }
+        disabled={!field.enable_analyzer}
         value={analyzer}
         variant="filled"
         label={collectionTrans('analyzer')}
       />
       <CustomIconButton
-        disabled={
-          !field.enable_analyzer && field.data_type !== DataTypeEnum.VarCharBM25
-        }
+        disabled={!field.enable_analyzer}
         onClick={handleSettingsClick}
       >
         <icons.settings sx={{ fontSize: '14px', marginLeft: '4px' }} />

+ 8 - 9
client/src/utils/Format.ts

@@ -5,7 +5,6 @@ import {
   VectorTypes,
   DataTypeStringEnum,
   DEFAULT_ANALYZER_PARAMS,
-  DataTypeEnum,
 } from '@/consts';
 import {
   CreateFieldType,
@@ -91,10 +90,13 @@ export const getEnumKeyByValue = (enumObj: any, enumValue: any) => {
 export const getObjFromKeyValuePair = (
   pairs: { key: string; value: any }[]
 ): { [key in string]: any } => {
-  const obj = pairs.reduce((acc, cur) => {
-    acc[cur.key] = cur.value;
-    return acc;
-  }, {} as { [key in string]: any });
+  const obj = pairs.reduce(
+    (acc, cur) => {
+      acc[cur.key] = cur.value;
+      return acc;
+    },
+    {} as { [key in string]: any }
+  );
   return obj;
 };
 
@@ -116,10 +118,7 @@ export const getCreateFieldType = (field: CreateField): CreateFieldType => {
     return 'defaultVector';
   }
 
-  if (
-    VectorTypes.includes(field.data_type) ||
-    field.data_type === DataTypeEnum.VarCharBM25
-  ) {
+  if (VectorTypes.includes(field.data_type)) {
     return 'vector';
   }