File_Content_Service implements Registerable, Standard_Service

Injects parsed attachment content into DVE indexing and manages cache storage.

Tags
author

Barn2 Plugins [email protected]

license

GPL-3.0

copyright

Barn2 Media Ltd

Interfaces, Classes and Traits

Registerable
Standard_Service

Table of Contents

ATTACHED_FILE_META  = '_wp_attached_file'
File attachment path metadata key.
ATTACHMENT_ID_META  = '_dlp_attached_file_id'
Metadata key storing attached file ID.
ATTRIBUTE_KEY  = 'file_content'
Search index attribute key.
ATTRIBUTE_WEIGHT  = 70
Relevance weight for file content attribute.
LINK_TYPE_META  = '_dlp_document_link_type'
Metadata key storing document link type.
PLUGIN_PREFIX  = 'dlp'
Plugin prefix used by DVE.
$table  : File_Content_Table
Table helper.
$table_available  : bool|null
Cached table existence check.
__construct()  : mixed
Constructor.
add_attribute_weight()  : array<string|int, mixed>
Add relevance weight for file content attribute.
add_file_content_attribute()  : array<string|int, mixed>
Add file content to searchable attributes for document posts.
adjust_batch_size_for_file_content()  : int
Reduce DVE batch size for safer document parsing runs.
cleanup_on_delete()  : mixed
Remove cache row when document post is deleted.
clear_failed_rows()  : mixed
Clear failed parser rows on explicit full reindex.
on_attachment_change()  : mixed
Queue affected documents when an attachment changes.
on_attachment_delete()  : mixed
Cleanup cache and queue affected documents when an attachment is deleted.
on_attachment_meta_change()  : mixed
Queue affected documents when attachment file path metadata changes.
register()  : mixed
{@inheritdoc}
apply_content_limits()  : string
Apply optional extracted-content byte limit.
delete_cache_by_attachment_id()  : mixed
Delete cache rows by attachment ID.
delete_cache_by_post_id()  : mixed
Delete cache rows by document post ID.
get_cache_row()  : array<string|int, mixed>|null
Fetch cache row by document post ID.
get_document_ids_for_attachment()  : array<string|int, int>
Get document IDs that reference a given attachment.
has_fast_sticky_error()  : bool
Determine if sticky error can be respected without recomputing file hash.
has_sticky_error()  : bool
Determine if we should skip retry because error is sticky.
is_attachment_modified_since_parse()  : bool
Check if attachment post has been modified since the cache row was parsed.
is_cache_hit()  : bool
Determine if the cache row is reusable.
is_fast_cache_hit()  : bool
Determine if cache can be reused without recomputing file hash.
is_fast_cache_validation_enabled()  : bool
Determine whether fast cache validation is enabled.
is_file_skipped_by_size()  : bool
Apply optional file size-based parse skip.
is_table_available()  : bool
Check if cache table is available.
log_parse_error()  : mixed
Log parser failures.
maybe_refresh_cache_metadata()  : mixed
Refresh cached metadata when a cache hit still points to old attachment details.
normalize_content()  : string
Normalize content to valid UTF-8 text.
queue_documents_for_reindex()  : mixed
Queue documents for DVE reindex.
resolve_mime_type()  : string
Resolve parse MIME type.
store_cache_error()  : mixed
Store parser failure row.
store_cache_success()  : mixed
Store successful parse row.
upsert_row()  : mixed
Insert or replace a row by post ID.

Constants

ATTACHED_FILE_META

File attachment path metadata key.

public mixed ATTACHED_FILE_META = '_wp_attached_file'
Tags

ATTACHMENT_ID_META

Metadata key storing attached file ID.

public mixed ATTACHMENT_ID_META = '_dlp_attached_file_id'
Tags

ATTRIBUTE_KEY

Search index attribute key.

public mixed ATTRIBUTE_KEY = 'file_content'
Tags

ATTRIBUTE_WEIGHT

Relevance weight for file content attribute.

public mixed ATTRIBUTE_WEIGHT = 70
Tags

Metadata key storing document link type.

public mixed LINK_TYPE_META = '_dlp_document_link_type'
Tags

Properties

$table_available

Cached table existence check.

private bool|null $table_available = null
Tags

Methods

add_attribute_weight()

Add relevance weight for file content attribute.

public add_attribute_weight(array<string|int, mixed> $weights[, string $plugin_prefix = '' ]) : array<string|int, mixed>
Parameters
$weights : array<string|int, mixed>

Attribute weights.

$plugin_prefix : string = ''

Plugin prefix.

Tags
Return values
array<string|int, mixed>

add_file_content_attribute()

Add file content to searchable attributes for document posts.

public add_file_content_attribute(array<string|int, mixed> $attributes, WP_Post $post) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Existing searchable attributes.

$post : WP_Post

Current post.

Tags
Return values
array<string|int, mixed>

adjust_batch_size_for_file_content()

Reduce DVE batch size for safer document parsing runs.

public adjust_batch_size_for_file_content(int $batch_size) : int
Parameters
$batch_size : int

Incoming batch size.

Tags
Return values
int

cleanup_on_delete()

Remove cache row when document post is deleted.

public cleanup_on_delete(int $post_id) : mixed
Parameters
$post_id : int

Post ID.

Tags
Return values
mixed

clear_failed_rows()

Clear failed parser rows on explicit full reindex.

public clear_failed_rows() : mixed
Tags
Return values
mixed

on_attachment_change()

Queue affected documents when an attachment changes.

public on_attachment_change(int $attachment_id) : mixed
Parameters
$attachment_id : int

Attachment ID.

Tags
Return values
mixed

on_attachment_delete()

Cleanup cache and queue affected documents when an attachment is deleted.

public on_attachment_delete(int $attachment_id) : mixed
Parameters
$attachment_id : int

Attachment ID.

Tags
Return values
mixed

on_attachment_meta_change()

Queue affected documents when attachment file path metadata changes.

public on_attachment_meta_change(int $meta_id, int $object_id, string $meta_key, mixed $meta_value) : mixed
Parameters
$meta_id : int

Meta ID.

$object_id : int

Object ID.

$meta_key : string

Meta key.

$meta_value : mixed

Meta value.

Tags
Return values
mixed

apply_content_limits()

Apply optional extracted-content byte limit.

private apply_content_limits(string $content, int $post_id, int $attachment_id) : string
Parameters
$content : string

Extracted content.

$post_id : int

Document post ID.

$attachment_id : int

Attachment ID.

Tags
Return values
string

delete_cache_by_attachment_id()

Delete cache rows by attachment ID.

private delete_cache_by_attachment_id(int $attachment_id) : mixed
Parameters
$attachment_id : int

Attachment ID.

Tags
Return values
mixed

delete_cache_by_post_id()

Delete cache rows by document post ID.

private delete_cache_by_post_id(int $post_id) : mixed
Parameters
$post_id : int

Post ID.

Tags
Return values
mixed

get_cache_row()

Fetch cache row by document post ID.

private get_cache_row(int $post_id) : array<string|int, mixed>|null
Parameters
$post_id : int

Document post ID.

Tags
Return values
array<string|int, mixed>|null

get_document_ids_for_attachment()

Get document IDs that reference a given attachment.

private get_document_ids_for_attachment(int $attachment_id) : array<string|int, int>
Parameters
$attachment_id : int

Attachment ID.

Tags
Return values
array<string|int, int>

has_fast_sticky_error()

Determine if sticky error can be respected without recomputing file hash.

private has_fast_sticky_error(array<string|int, mixed>|null $row, int $post_id, int $attachment_id, string $mime_type, int $file_size, string $parser_version) : bool
Parameters
$row : array<string|int, mixed>|null

Cache row.

$post_id : int

Post ID.

$attachment_id : int

Attachment ID.

$mime_type : string

MIME type.

$file_size : int

File size.

$parser_version : string

Parser version.

Tags
Return values
bool

has_sticky_error()

Determine if we should skip retry because error is sticky.

private has_sticky_error(array<string|int, mixed>|null $row, string $file_hash, string $parser_version) : bool
Parameters
$row : array<string|int, mixed>|null

Cache row.

$file_hash : string

File hash.

$parser_version : string

Parser version.

Tags
Return values
bool

is_attachment_modified_since_parse()

Check if attachment post has been modified since the cache row was parsed.

private is_attachment_modified_since_parse(int $attachment_id, array<string|int, mixed> $row) : bool
Parameters
$attachment_id : int

Attachment ID.

$row : array<string|int, mixed>

Cache row.

Tags
Return values
bool

is_cache_hit()

Determine if the cache row is reusable.

private is_cache_hit(array<string|int, mixed>|null $row, string $file_hash, string $parser_version) : bool
Parameters
$row : array<string|int, mixed>|null

Cache row.

$file_hash : string

File hash.

$parser_version : string

Parser version.

Tags
Return values
bool

is_fast_cache_hit()

Determine if cache can be reused without recomputing file hash.

private is_fast_cache_hit(array<string|int, mixed>|null $row, int $post_id, int $attachment_id, string $mime_type, int $file_size, string $parser_version) : bool
Parameters
$row : array<string|int, mixed>|null

Cache row.

$post_id : int

Post ID.

$attachment_id : int

Attachment ID.

$mime_type : string

MIME type.

$file_size : int

File size.

$parser_version : string

Parser version.

Tags
Return values
bool

is_fast_cache_validation_enabled()

Determine whether fast cache validation is enabled.

private is_fast_cache_validation_enabled(int $post_id, int $attachment_id) : bool
Parameters
$post_id : int

Document post ID.

$attachment_id : int

Attachment ID.

Tags
Return values
bool

is_file_skipped_by_size()

Apply optional file size-based parse skip.

private is_file_skipped_by_size(int $file_size, int $post_id, int $attachment_id) : bool
Parameters
$file_size : int

File size in bytes.

$post_id : int

Post ID.

$attachment_id : int

Attachment ID.

Tags
Return values
bool

is_table_available()

Check if cache table is available.

private is_table_available() : bool
Tags
Return values
bool

log_parse_error()

Log parser failures.

private log_parse_error(int $post_id, string $message) : mixed
Parameters
$post_id : int

Document post ID.

$message : string

Error message.

Tags
Return values
mixed

maybe_refresh_cache_metadata()

Refresh cached metadata when a cache hit still points to old attachment details.

private maybe_refresh_cache_metadata(array<string|int, mixed> $row, int $post_id, int $attachment_id, string $content, string $file_hash, string $parser_version, string $mime_type, int $file_size) : mixed
Parameters
$row : array<string|int, mixed>

Cache row.

$post_id : int

Document post ID.

$attachment_id : int

Attachment ID.

$content : string

Cached content.

$file_hash : string

File hash.

$parser_version : string

Parser version.

$mime_type : string

MIME type.

$file_size : int

File size.

Tags
Return values
mixed

normalize_content()

Normalize content to valid UTF-8 text.

private normalize_content(string $content) : string
Parameters
$content : string

Raw content.

Tags
Return values
string

queue_documents_for_reindex()

Queue documents for DVE reindex.

private queue_documents_for_reindex(array<string|int, int> $document_ids) : mixed
Parameters
$document_ids : array<string|int, int>

Document IDs.

Tags
Return values
mixed

resolve_mime_type()

Resolve parse MIME type.

private resolve_mime_type(int $attachment_id, string $file_path) : string
Parameters
$attachment_id : int

Attachment ID.

$file_path : string

File path.

Tags
Return values
string

store_cache_error()

Store parser failure row.

private store_cache_error(int $post_id, int $attachment_id, string $file_hash, string $parser_version, string $mime_type, int $file_size, string $error_message) : mixed
Parameters
$post_id : int

Document post ID.

$attachment_id : int

Attachment ID.

$file_hash : string

File hash.

$parser_version : string

Parser version.

$mime_type : string

MIME type.

$file_size : int

File size.

$error_message : string

Error message.

Tags
Return values
mixed

store_cache_success()

Store successful parse row.

private store_cache_success(int $post_id, int $attachment_id, string $content, string $file_hash, string $parser_version, string $mime_type, int $file_size) : mixed
Parameters
$post_id : int

Document post ID.

$attachment_id : int

Attachment ID.

$content : string

Extracted content.

$file_hash : string

File hash.

$parser_version : string

Parser version.

$mime_type : string

MIME type.

$file_size : int

File size.

Tags
Return values
mixed

upsert_row()

Insert or replace a row by post ID.

private upsert_row(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>

Row data.

Tags
Return values
mixed

Search results