Update search

This commit is contained in:
Daniel Supernault 2019-04-17 20:36:14 -06:00
parent 3810d213d6
commit 44a60d745b
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
3 changed files with 31 additions and 19 deletions

View file

@ -9,6 +9,7 @@ use App\Status;
use Illuminate\Http\Request;
use App\Util\ActivityPub\Helpers;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use App\Transformer\Api\{
AccountTransformer,
HashtagTransformer,
@ -22,11 +23,14 @@ class SearchController extends Controller
$this->middleware('auth');
}
public function searchAPI(Request $request, $tag)
public function searchAPI(Request $request)
{
if(mb_strlen($tag) < 3) {
return;
}
$this->validate($request, [
'q' => 'required|string|min:3|max:120',
'src' => 'required|string|in:metro',
'v' => 'required|integer|in:1'
]);
$tag = $request->input('q');
$tag = e(urldecode($tag));
$hash = hash('sha256', $tag);
@ -65,7 +69,12 @@ class SearchController extends Controller
}
}
}
$hashtags = Hashtag::select('id', 'name', 'slug')->where('slug', 'like', '%'.$tag.'%')->whereHas('posts')->limit(20)->get();
$htag = Str::startsWith($tag, '#') == true ? mb_substr($tag, 1) : $tag;
$hashtags = Hashtag::select('id', 'name', 'slug')
->where('slug', 'like', '%'.$htag.'%')
->whereHas('posts')
->limit(20)
->get();
if($hashtags->count() > 0) {
$tags = $hashtags->map(function ($item, $key) {
return [

View file

@ -124,17 +124,22 @@ export default {
},
methods: {
fetchSearchResults() {
axios.get('/api/search/' + encodeURI(this.query))
.then(res => {
let results = res.data;
this.results.hashtags = results.hashtags;
this.results.profiles = results.profiles;
this.results.statuses = results.posts;
this.loading = false;
}).catch(err => {
this.loading = false;
// this.networkError = true;
})
axios.get('/api/search', {
params: {
'q': this.query,
'src': 'metro',
'v': 1
}
}).then(res => {
let results = res.data;
this.results.hashtags = results.hashtags;
this.results.profiles = results.profiles;
this.results.statuses = results.posts;
this.loading = false;
}).catch(err => {
this.loading = false;
// this.networkError = true;
})
},
followProfile(id) {

View file

@ -64,9 +64,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('discover', 'DiscoverController@home')->name('discover');
Route::group(['prefix' => 'api'], function () {
Route::get('search/{tag}', 'SearchController@searchAPI')
//->where('tag', '.*');
->where('tag', '[A-Za-z0-9]+');
Route::get('search', 'SearchController@searchAPI');
Route::get('nodeinfo/2.0.json', 'FederationController@nodeinfo');
Route::group(['prefix' => 'v1'], function () {