Recent

Search_RetrieverclassPro only

Search_Retriever

Retrieves articles with the standard WordPress search used by the knowledge base.

Each keyword is searched on its own and articles are ranked by the keywords they match, rarer keywords counting for more. This handles natural-language questions, which rarely match every word, and doesn’t depend on how the site’s search combines words: search plugins may match any word rather than all of them. Long questions keep their rarest keywords, which say most about the topic. Both passes use WP_Query, so language plugins and other query filters still apply.

Namespace: WebberZone\Knowledge_Base\Pro\AI
Since: 3.2.0
Source: includes/pro/ai/class-search-retriever.php line 26 Implements: Retriever_Interface

Methods

__construct()

Constructor.

Line: 89

public function __construct( int $max_chars = ... );
Type Name Description
int $max_chars Maximum characters of plain text per article. 0 uses the setting.

retrieve()

Retrieve articles relevant to a question.

Since: 3.2.0
Line: 102

public function retrieve( string $question, int $limit ): array;
Type Name Description
string $question Visitor question.
int $limit Maximum number of articles.

Returns: array — Articles, most relevant first.

prepare_article()

Build the article data sent as context.

Since: 3.2.0
Line: 140

public function prepare_article( WP_Post $post ): array;
Type Name Description
\WP_Post $post Article.

Returns: array — Article data.

get_plain_text()

Convert an article to plain text trimmed to the character limit.

Blocks are rendered, shortcodes stripped, HTML removed and whitespace collapsed. Block-level elements become line breaks so the text keeps its structure.

Since: 3.2.0
Line: 160

public function get_plain_text( WP_Post $post ): string;
Type Name Description
\WP_Post $post Article.

Returns: string — Plain text.

skip_block()

Skip blocks that add navigation or listings rather than article content.

Since: 3.2.0
Line: 188

public function skip_block( $pre_render, $parsed_block ): string|null;
Type Name Description
string|null $pre_render Short-circuit value.
array $parsed_block Parsed block.

Returns: string|null — Empty string to skip the block, otherwise the original value.

get_skipped_blocks() static

Blocks left out of the article text.

Since: 3.2.0
Line: 205

static public function get_skipped_blocks(  ): array;

Returns: array — Block names.

html_to_text() static

Convert HTML to plain text.

Since: 3.2.0
Line: 241

static public function html_to_text( string $html ): string;
Type Name Description
string $html HTML.

Returns: string — Plain text with collapsed whitespace.

trim_text() static

Trim text to a maximum length, preferring a word boundary.

Since: 3.2.0
Line: 261

static public function trim_text( string $text, int $max_chars ): string;
Type Name Description
string $text Text.
int $max_chars Maximum characters, including the ellipsis.

Returns: string — Trimmed text.

extract_keywords() static

Extract search keywords from a question.

Since: 3.2.0
Line: 286

static public function extract_keywords( string $question, int $max = ... ): array;
Type Name Description
string $question Question.
int $max Maximum number of keywords, in question order.

Returns: array — Keywords.

get_stop_words() static

Words dropped from questions before searching.

Since: 3.2.0
Line: 315

static public function get_stop_words(  ): array;

Returns: array — Stop words.