mirror of https://github.com/pixelfed/pixelfed.git
Update search
This commit is contained in:
parent
3810d213d6
commit
44a60d745b
|
@ -9,6 +9,7 @@ use App\Status;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Util\ActivityPub\Helpers;
|
use App\Util\ActivityPub\Helpers;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use App\Transformer\Api\{
|
use App\Transformer\Api\{
|
||||||
AccountTransformer,
|
AccountTransformer,
|
||||||
HashtagTransformer,
|
HashtagTransformer,
|
||||||
|
@ -22,11 +23,14 @@ class SearchController extends Controller
|
||||||
$this->middleware('auth');
|
$this->middleware('auth');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function searchAPI(Request $request, $tag)
|
public function searchAPI(Request $request)
|
||||||
{
|
{
|
||||||
if(mb_strlen($tag) < 3) {
|
$this->validate($request, [
|
||||||
return;
|
'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));
|
$tag = e(urldecode($tag));
|
||||||
|
|
||||||
$hash = hash('sha256', $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) {
|
if($hashtags->count() > 0) {
|
||||||
$tags = $hashtags->map(function ($item, $key) {
|
$tags = $hashtags->map(function ($item, $key) {
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -124,17 +124,22 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchSearchResults() {
|
fetchSearchResults() {
|
||||||
axios.get('/api/search/' + encodeURI(this.query))
|
axios.get('/api/search', {
|
||||||
.then(res => {
|
params: {
|
||||||
let results = res.data;
|
'q': this.query,
|
||||||
this.results.hashtags = results.hashtags;
|
'src': 'metro',
|
||||||
this.results.profiles = results.profiles;
|
'v': 1
|
||||||
this.results.statuses = results.posts;
|
}
|
||||||
this.loading = false;
|
}).then(res => {
|
||||||
}).catch(err => {
|
let results = res.data;
|
||||||
this.loading = false;
|
this.results.hashtags = results.hashtags;
|
||||||
// this.networkError = true;
|
this.results.profiles = results.profiles;
|
||||||
})
|
this.results.statuses = results.posts;
|
||||||
|
this.loading = false;
|
||||||
|
}).catch(err => {
|
||||||
|
this.loading = false;
|
||||||
|
// this.networkError = true;
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
followProfile(id) {
|
followProfile(id) {
|
||||||
|
|
|
@ -64,9 +64,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
|
||||||
Route::get('discover', 'DiscoverController@home')->name('discover');
|
Route::get('discover', 'DiscoverController@home')->name('discover');
|
||||||
|
|
||||||
Route::group(['prefix' => 'api'], function () {
|
Route::group(['prefix' => 'api'], function () {
|
||||||
Route::get('search/{tag}', 'SearchController@searchAPI')
|
Route::get('search', 'SearchController@searchAPI');
|
||||||
//->where('tag', '.*');
|
|
||||||
->where('tag', '[A-Za-z0-9]+');
|
|
||||||
Route::get('nodeinfo/2.0.json', 'FederationController@nodeinfo');
|
Route::get('nodeinfo/2.0.json', 'FederationController@nodeinfo');
|
||||||
|
|
||||||
Route::group(['prefix' => 'v1'], function () {
|
Route::group(['prefix' => 'v1'], function () {
|
||||||
|
|
Loading…
Reference in New Issue