Commit 644774cb authored by 劉冠偉's avatar 劉冠偉

検索結果順序を修復

parent d3160745
......@@ -18,7 +18,8 @@ class SearchController extends Controller
public function all($kanji){
$books= DB::table('books')->orderBy('date_order','asc')->pluck('type','id');
$codes= DB::table('books')->pluck('no','id');
// dd($types);
$date_order=DB::table('books')->pluck('date_order','id');
$chars=HNG::where('entry','=',$kanji)->orWhere('variants','like','%'.$kanji.'%')->first();
$results=array();
if(is_Null($chars)){
......@@ -30,7 +31,7 @@ class SearchController extends Controller
foreach($books as $book=>$type){
if(Schema::hasTable($book)){ //check if table exists
$query=DB::table('main')->join($book,'main.id',$book.'.id')->where('entry','=',$kanji)->orWhere('variants','like','%'.$kanji.'%')->get();
// dd($query[0]->glyph_num);
if(preg_match('/ \(H(\d+)\)/',$codes[$book],$temp_fcode)){
$fcode=(int)$temp_fcode[1];
}else{
......@@ -38,7 +39,7 @@ class SearchController extends Controller
}
if($query->isNotEmpty()){
$query->map(function($record) use ($fcode, $book){
$query->map(function($record) use ($fcode, $book, $date_order){
$temp =array($record)[0];
$num= $record->glyph_num;
......@@ -63,14 +64,31 @@ class SearchController extends Controller
// dd($charID);
$temp->chisechar=$book.'='.$charID;
$temp->hngcard=$fcode.'-'.$cardnum;
$temp->date_order=$date_order[$book];
return array($temp);
});
$results[$type][$book]=$query;
}
// query builderのselect()を使ったらエラになっちゃう。phpのせいらしい
}else {
// dd($book.' list table do not exist!');
}
}
// 年代順
foreach($results as $key=>$type){
if(is_array($type)){
foreach ($type as $kk => $vv) {
$date[$kk] = $vv[0]->date_order;
}
array_multisort($date, SORT_ASC, $type);
$date=[];
$results[$key]=$type;
}
}
return response()->json($results);
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment