質問編集履歴
1
更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -39,3 +39,147 @@
|
|
39
39
|
|
40
40
|
|
41
41
|
よろしくお願いいたします。
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
public static function searchCommon($where = null, $sortFunc = null)
|
48
|
+
|
49
|
+
{
|
50
|
+
|
51
|
+
$input = request()->all();
|
52
|
+
|
53
|
+
$validator = \Validator::make($input, [
|
54
|
+
|
55
|
+
'q' => 'string|max:255',
|
56
|
+
|
57
|
+
'page' => 'integer|not_in:0,1',
|
58
|
+
|
59
|
+
'search' => 'integer'
|
60
|
+
|
61
|
+
]);
|
62
|
+
|
63
|
+
if ($validator->fails()) return app()->abort(404);
|
64
|
+
|
65
|
+
$page = isset($input['page']) ? (int)$input['page'] : 1;
|
66
|
+
|
67
|
+
$search = isset($input['search']) ? (int)$input['search'] : 0;dd($input['search']);
|
68
|
+
|
69
|
+
if ($search) {
|
70
|
+
|
71
|
+
$data = Search::select('result', 'query')->where('id', $search)->first();
|
72
|
+
|
73
|
+
$ids = $data ? $data['result'] : [];
|
74
|
+
|
75
|
+
$q = isset($data['query']['q']) ? $data['query']['q'] : '';
|
76
|
+
|
77
|
+
} else {
|
78
|
+
|
79
|
+
$q = isset($input['q']) ? $input['q'] : '';
|
80
|
+
|
81
|
+
$query = Fulltext::where('type', '<>', 'job');
|
82
|
+
|
83
|
+
if ($q !== '') $query->whereIndex($q);
|
84
|
+
|
85
|
+
if (!is_null($where)) $query->where($where);
|
86
|
+
|
87
|
+
$ids = NULL;
|
88
|
+
|
89
|
+
if ($sortFunc) {
|
90
|
+
|
91
|
+
$query = $query->select('id', 'type', 'main_id')->get()->toArray();
|
92
|
+
|
93
|
+
usort($query, $sortFunc);
|
94
|
+
|
95
|
+
$ids = array_pluck($query, 'id');
|
96
|
+
|
97
|
+
} else {
|
98
|
+
|
99
|
+
$ids = array_map('intval', $query->orderBy('time','DESC')->lists('id')->toArray());
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
$search = new Search();
|
104
|
+
|
105
|
+
$search['result'] = $ids;
|
106
|
+
|
107
|
+
$search['query'] = ['q' => $q];dd($search);
|
108
|
+
|
109
|
+
$search->save();
|
110
|
+
|
111
|
+
$search = $search['id'];
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
下の方にある「$search['query'] = ['q' => $q];」にてdd($search);をかけたところ
|
120
|
+
|
121
|
+
下記のような表示がなされます。
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
```
|
126
|
+
|
127
|
+
Search {#304 ▼
|
128
|
+
|
129
|
+
#table: "searches"
|
130
|
+
|
131
|
+
#casts: array:3 [▶]
|
132
|
+
|
133
|
+
#connection: null
|
134
|
+
|
135
|
+
#primaryKey: "id"
|
136
|
+
|
137
|
+
#perPage: 15
|
138
|
+
|
139
|
+
+incrementing: true
|
140
|
+
|
141
|
+
+timestamps: true
|
142
|
+
|
143
|
+
#attributes: array:2 [▼
|
144
|
+
|
145
|
+
"result" => "[]"
|
146
|
+
|
147
|
+
"query" => "{"q":"\u91d1\u5c71"}"
|
148
|
+
|
149
|
+
]
|
150
|
+
|
151
|
+
#original: []
|
152
|
+
|
153
|
+
#relations: []
|
154
|
+
|
155
|
+
#hidden: []
|
156
|
+
|
157
|
+
#visible: []
|
158
|
+
|
159
|
+
#appends: []
|
160
|
+
|
161
|
+
#fillable: []
|
162
|
+
|
163
|
+
#guarded: array:1 [▶]
|
164
|
+
|
165
|
+
#dates: []
|
166
|
+
|
167
|
+
#dateFormat: null
|
168
|
+
|
169
|
+
#touches: []
|
170
|
+
|
171
|
+
#observables: []
|
172
|
+
|
173
|
+
#with: []
|
174
|
+
|
175
|
+
#morphClass: null
|
176
|
+
|
177
|
+
+exists: false
|
178
|
+
|
179
|
+
+wasRecentlyCreated: false
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
```
|
184
|
+
|
185
|
+
上記は「会計」で検索しようとして表示された文字化けとなります。
|