$args * @param array $assoc */ public function refresh(array $args, array $assoc): void { \WordPress\CloudflareWorkersAiProvider\Activity\Recorder::start('related', 'related_build'); if (!Related::enabled()) { \WP_CLI::error('Related posts are off. Switch them on in AIPCF > Features > Related posts.'); } if (isset($assoc['all'])) { $reset = IndexTable::resetRelated(); \WP_CLI::log(sprintf($reset === 1 ? '%d list marked to be built again.' : '%d lists marked to be built again.', $reset)); } $total = 0; do { $r = Related::refresh(microtime(true) + 30); $total += $r['done']; $c = IndexTable::relatedCounts(); \WP_CLI::log(sprintf('%d built. %d posts with a list, %d waiting.', $total, $c['done'], $c['waiting'])); } while ($r['done'] > 0 && $r['stopped'] === ''); if ($r['stopped'] !== '') { \WP_CLI::warning($r['stopped']); } \WP_CLI::success(sprintf( $total === 1 ? 'Built %d related list. Posts embedded in the last %d minutes wait until the vector store can find them.' : 'Built %d related lists. Posts embedded in the last %d minutes wait until the vector store can find them.', $total, (int) ceil(Related::SETTLE / 60) )); } /** * Shows a post's related list with similarity scores (0 to 1). * * ## OPTIONS * * * : Post ID. * * @param list $args * @param array $assoc */ public function show(array $args, array $assoc): void { $id = (int) ($args[0] ?? 0); $list = Related::stored($id); if ($list === null) { \WP_CLI::error(sprintf('Post %d has no related list yet.', $id)); } $min = (float) Settings::get('related_min_score'); foreach ($list as $pid => $score) { \WP_CLI::log(sprintf('%s %.3f #%d %s', $score >= $min ? ' ' : '-', $score, $pid, html_entity_decode(get_the_title($pid), ENT_QUOTES, 'UTF-8'))); } \WP_CLI::log(sprintf('(- = below the minimum similarity %.2f, a %d%% match: not shown)', $min, (int) round($min * 100))); } }