|
|
@@ -6,6 +6,7 @@ use App\Models\Vocabulary;
|
|
|
use Illuminate\Http\Request;
|
|
|
use App\Http\Resources\VocabularyResource;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class VocabularyController extends Controller
|
|
|
{
|
|
|
@@ -20,9 +21,11 @@ class VocabularyController extends Controller
|
|
|
switch ($request->get("view")) {
|
|
|
case 'key':
|
|
|
$key = $request->get("key");
|
|
|
- $result = Cache::remember("/dict_vocabulary/{$key}",60,function() use($key){
|
|
|
- return Vocabulary::where('word','like',$key."%")
|
|
|
+ $result = Cache::remember("/dict_vocabulary/{$key}",10,function() use($key){
|
|
|
+ return Vocabulary::whereRaw('word like ? or word_en like ?',[$key."%",$key."%"])
|
|
|
->whereOr('word_en','like',$key."%")
|
|
|
+ ->orderBy('strlen')
|
|
|
+ ->orderBy('word')
|
|
|
->take(10)->get();
|
|
|
});
|
|
|
return $this->ok(['rows'=>VocabularyResource::collection($result),'count'=>count($result)]);
|