Explorar o código

Merge pull request #1966 from visuddhinanda/agile

按照长度和数量计算权重
visuddhinanda %!s(int64=2) %!d(string=hai) anos
pai
achega
396aeb2f98

+ 1 - 0
dashboard/src/components/api/Dict.ts

@@ -76,6 +76,7 @@ export interface IVocabularyData {
   word: string;
   count: number;
   meaning?: string;
+  strlen: number;
 }
 export interface IVocabularyListResponse {
   ok: boolean;

+ 18 - 3
dashboard/src/components/dict/SearchVocabulary.tsx

@@ -101,9 +101,24 @@ const SearchVocabularyWidget = ({
 
     get<IVocabularyListResponse>(`/v2/${api}?view=key&key=${value}`)
       .then((json) => {
-        const words: ValueType[] = json.data.rows.map((item) => {
-          return renderItem(item.word, item.count, item.meaning);
-        });
+        const words: ValueType[] = json.data.rows
+          .map((item) => {
+            let weight = item.count / item.strlen;
+            if (item.word.length === value.length) {
+              weight = 100;
+            }
+            return {
+              word: item.word,
+              count: item.count,
+              meaning: item.meaning,
+              weight: weight,
+            };
+          })
+          .sort((a, b) => b.weight - a.weight)
+          .map((item) => {
+            return renderItem(item.word, item.count, item.meaning);
+          });
+
         setOptions(words);
       })
       .finally(() => {