Browse Source

Merge pull request #1965 from visuddhinanda/laravel

add strlen
visuddhinanda 2 years ago
parent
commit
d227573346

+ 2 - 2
app/Http/Controllers/VocabularyController.php

@@ -25,11 +25,11 @@ class VocabularyController extends Controller
                 $result = RedisClusters::remember("/dict_vocabulary/{$key}",
                         config('mint.cache.expire'),
                         function() use($key){
-                        return Vocabulary::whereRaw('word like ? or word_en like ?',[$key."%",$key."%"])
+                            return Vocabulary::where('word', 'like',$key."%")
                                     ->whereOr('word_en','like',$key."%")
                                     ->orderBy('strlen')
                                     ->orderBy('word')
-                                    ->take(10)->get();
+                                    ->take(50)->get();
                 });
                 return $this->ok(['rows'=>VocabularyResource::collection($result),'count'=>count($result)]);
                 break;

+ 1 - 0
app/Http/Resources/VocabularyResource.php

@@ -21,6 +21,7 @@ class VocabularyResource extends JsonResource
         return [
             "word"=>$this['word'],
             "count"=> $this['count'],
+            "strlen"=> $this['strlen'],
             "meaning"=> $dictMeaning->get($this['word'],$request->get("lang","zh-Hans")),
         ];
     }