Update (kernel): Auto submit index

This commit is contained in:
2023-11-23 03:38:45 +08:00
parent b2762ecef2
commit 416f06b344
8 changed files with 139 additions and 11 deletions

View File

@@ -5,6 +5,8 @@
use App\Jobs\BrowseDFSAndWriteWithAIJob;
use App\Jobs\BrowseRSSPostJob;
use App\Jobs\PublishIndexPostJob;
use App\Jobs\PublishRssSearchResultJob;
use App\Models\HybridTopRssPostKeywords;
use App\Models\Post;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@@ -22,6 +24,17 @@ protected function schedule(Schedule $schedule): void
BrowseRSSPostJob::dispatch(1)->onQueue('default')->onConnection('default');
})->hourly()->name('browse-rss-post-job-hourly');
$schedule->call(function () {
$top_rss_keywords = HybridTopRssPostKeywords::get(1, 20);
foreach ($top_rss_keywords as $rss_keyword)
{
PublishRssSearchResultJob::dispatch($rss_keyword->value_lowercased)->onQueue('default')->onConnection('default');
}
})->twiceDaily(0, 12)->name('top-rss-keywords-indexing-daily');
// $schedule->call(function () {
// BrowseDFSAndWriteWithAIJob::dispatch()->onQueue('default')->onConnection('default');
// })->everySixHours()->name('write-a-job-6hrs');

View File

@@ -5,6 +5,8 @@
use App\Http\Controllers\Controller;
use App\Models\Post;
use App\Models\RssPost;
use App\Models\HybridTopRssPostKeywords;
use Artesaos\SEOTools\Facades\SEOMeta;
use Artesaos\SEOTools\Facades\SEOTools;
use GrahamCampbell\Markdown\Facades\Markdown;
@@ -25,9 +27,11 @@ public function home(Request $request)
// $query->whereNotIn('id', $featured_posts->pluck('id')->toArray());
// })->where('status', 'publish')->where('published_at', '<=', now())->orderBy('published_at', 'desc')->limit(10)->get();
$top_rss_keywords = HybridTopRssPostKeywords::get(1, 10);
$rss_posts = RssPost::with('entities_keywords')->where('status', 'published')->orderBy('published_at', 'desc')->paginate(15);
return response(view('front.welcome', compact('rss_posts')), 200);
return response(view('front.welcome', compact('rss_posts','top_rss_keywords')), 200);
}
public function terms(Request $request)

View File

@@ -29,7 +29,7 @@ public function searchResults(Request $request, $query)
$breadcrumbs = collect([
['name' => 'Home', 'url' => route('front.home')],
['name' => 'News Bites', 'url' => route('front.all')],
['name' => $query, 'url' => null],
['name' => '#'.$query, 'url' => null],
]);
$title = 'Latest News about '.ucwords($query).' in FutureWalker';

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Jobs;
use App\Jobs\Tasks\PublishIndexPostTask;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;
use LaravelGoogleIndexing;
use Exception;
class PublishRssSearchResultJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $query;
public $timeout = 30;
/**
* Create a new job instance.
*/
public function __construct(string $query)
{
$this->query = $query;
}
/**
* Execute the job.
*/
public function handle(): void
{
if ((app()->environment() == 'production') && (config('platform.global.indexing'))) {
$url = get_route_search_result(strtolower($this->query));
try {
IndexNow::submit($url);
} catch (Exception) {
}
try {
LaravelGoogleIndexing::create()->update($url);
} catch (Exception) {
}
}
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;
class HybridTopRssPostKeywords extends Model
{
// Disable timestamps as this is not a table model
public $timestamps = false;
// Define fillable attributes
protected $fillable = ['value', 'value_lowercased', 'value_count'];
// Override the table and primary key as this is an abstract model
protected $table = null;
protected $primaryKey = null;
// Disable incrementing as this is an abstract model
public $incrementing = false;
// Static method to get top keywords
public static function get($days = 1, $limit = 10)
{
return Cache::remember('top_rss_post_keywords_by_day_'.$days.'_'.$limit, 180, function () use ($days, $limit) {
$queryResults = DB::table('rss_post_keywords')
->select('value', 'value_lowercased', DB::raw('COUNT(value_lowercased) as value_count'))
->where('created_at', '>=', now()->subDays($days))
->groupBy('value', 'value_lowercased')
->orderBy(DB::raw('COUNT(value_lowercased)'), 'desc')
->limit($limit)
->get();
return self::hydrate($queryResults->toArray());
});
}
}