class fulltext_postgres extends base implements search_backend_interface

Fulltext search for PostgreSQL

Constants

SEARCH_RESULT_NOT_IN_CACHE

SEARCH_RESULT_IN_CACHE

SEARCH_RESULT_INCOMPLETE

private BATCH_SIZE

Properties

protected service $cache from  base
protected config $config from  base
protected driver_interface $db from  base
protected user $user from  base
protected array $stats

Associative array holding index stats

protected array $split_words

Holds the words entered by user, obtained by splitting the entered query on whitespace

protected string $tsearch_query

Stores the tsearch query

$phrase_search

True if phrase search is supported.

protected dispatcher_interface $phpbb_dispatcher

phpBB event dispatcher object

protected language $language
protected string $search_query

Contains tidied search query.

protected array $common_words

Contains common words.

protected array $word_length

Associative array stores the min and max word length to be searched

Methods

__construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $phpbb_root_path, string $phpEx)

Constructor Creates a new \phpbb\search\backend\fulltext_postgres, which is used as a search backend

int
obtain_ids(string $search_key, int $result_count, array $id_ary, int $start, int $per_page, string $sort_dir)

Retrieves cached search results

from  base
void
save_ids(string $search_key, string $keywords, array $author_ary, int $result_count, array $id_ary, int $start, string $sort_dir)

Caches post/topic ids

from  base
void
destroy_cache(array $words, array|bool $authors = false)

Removes old entries from the search results table and removes searches with keywords that contain a word in $words.

from  base
array|null
create_index(int $post_counter = 0)

Create fulltext index

array|null
delete_index(int $post_counter = null)

Drop fulltext index

array
forum_ids_with_indexing_enabled()

Return the ids of the forums that have indexing enabled

from  base
get_posts_batch_after(int $post_id)

Get batch of posts after id

from  base
int
get_max_post_id()

Get post with higher id

from  base
string
get_type()

Gets backend class

from  base
string
get_name()

Returns the name of this search backend to be displayed to administrators

bool
is_available()

Returns if the search engine is available

string|false
init()

Method executed when a search backend is set from acp.

string
get_search_query()

Returns the search_query

array
get_common_words()

Returns the common_words array

array|false
get_word_length()

Returns the word_length array

bool
split_keywords(string $keywords, string $terms)

Splits keywords entered by a user into an array of words stored in $this->split_words This function fills $this->search_query with the cleaned user search query

bool|int
keyword_search(string $type, string $fields, string $terms, array $sort_by_sql, string $sort_key, string $sort_dir, string $sort_days, array $ex_fid_ary, string $post_visibility, int $topic_id, array $author_ary, string $author_name, array $id_ary, int $start, int $per_page)

Performs a search on keywords depending on display specific params. You have to run split_keywords() first

bool|int
author_search(string $type, bool $firstpost_only, array $sort_by_sql, string $sort_key, string $sort_dir, string $sort_days, array $ex_fid_ary, string $post_visibility, int $topic_id, array $author_ary, string $author_name, array $id_ary, int $start, int $per_page)

Performs a search on an author's posts without caring about message contents. Depends on display specific params

bool
supports_phrase_search()

Returns if phrase search is supported or not

index(string $mode, int $post_id, string $message, string $subject, int $poster_id, int $forum_id)

Updates wordlist and wordmatch tables when a message is posted or changed Destroys cached search results, that contained one of the new words in a post so the results won't be outdated

void
index_remove(array $post_ids, array $author_ids, array $forum_ids)

Destroy cached results, that might be outdated after deleting a post

void
tidy()

Destroy old cache entries

bool
index_created()

Returns true if both FULLTEXT indexes exist

array|false
index_stats()

Returns an associative array containing information about the indexes

get_stats()

{@inheritdoc}

array
split_message(string $text)

Turns text into an array of words

array
get_acp_options()

Display various options that can be configured for the backend from the acp

Details

at line 95
__construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $phpbb_root_path, string $phpEx)

Constructor Creates a new \phpbb\search\backend\fulltext_postgres, which is used as a search backend

Parameters

config $config
driver_interface $db
dispatcher_interface $phpbb_dispatcher

Event dispatcher object

language $language
user $user
string $phpbb_root_path

Relative path to phpBB root

string $phpEx

PHP file extension

in base at line 82
protected int obtain_ids(string $search_key, int $result_count, array $id_ary, int $start, int $per_page, string $sort_dir)

Retrieves cached search results

Parameters

string $search_key

an md5 string generated from all the passed search options to identify the results

int $result_count

will contain the number of all results for the search (not only for the current page)

array $id_ary

is filled with the ids belonging to the requested page that are stored in the cache

int $start

indicates the first index of the page

int $per_page

number of ids each page is supposed to contain

string $sort_dir

is either a or d representing ASC and DESC

Return Value

int

self::SEARCH_RESULT_NOT_IN_CACHE or self::SEARCH_RESULT_IN_CACHE or self::SEARCH_RESULT_INCOMPLETE

in base at line 161
protected void save_ids(string $search_key, string $keywords, array $author_ary, int $result_count, array $id_ary, int $start, string $sort_dir)

Caches post/topic ids

Parameters

string $search_key

an md5 string generated from all the passed search options to identify the results

string $keywords

contains the keywords as entered by the user

array $author_ary

an array of author ids, if the author should be ignored during the search the array is empty

int $result_count

contains the number of all results for the search (not only for the current page)

array $id_ary

contains a list of post or topic ids that shall be cached, the first element must have the absolute index $start in the result set.

int $start

indicates the first index of the page

string $sort_dir

is either a or d representing ASC and DESC

Return Value

void

in base at line 271
protected void destroy_cache(array $words, array|bool $authors = false)

Removes old entries from the search results table and removes searches with keywords that contain a word in $words.

Parameters

array $words
array|bool $authors

Return Value

void

at line 869
array|null create_index(int $post_counter = 0)

Create fulltext index

Parameters

int $post_counter

Return Value

array|null

array with current status or null if finished

at line 928
array|null delete_index(int $post_counter = null)

Drop fulltext index

Parameters

int $post_counter

Return Value

array|null

array with current status or null if finished

in base at line 425
protected array forum_ids_with_indexing_enabled()

Return the ids of the forums that have indexing enabled

Return Value

array

in base at line 451
protected Generator get_posts_batch_after(int $post_id)

Get batch of posts after id

Parameters

int $post_id

Return Value

Generator

in base at line 470
protected int get_max_post_id()

Get post with higher id

Return Value

int

in base at line 484
string get_type()

Gets backend class

Return Value

string

at line 117
string get_name()

Returns the name of this search backend to be displayed to administrators

Return Value

string

Name

at line 125
bool is_available()

Returns if the search engine is available

Return Value

bool

at line 133
string|false init()

Method executed when a search backend is set from acp.

Checks permissions and paths, if everything is correct it generates the config file

Return Value

string|false

False if everything was ok or string with error message

at line 146
string get_search_query()

Returns the search_query

Return Value

string

search query

at line 154
array get_common_words()

Returns the common_words array

Return Value

array

common words that are ignored by search backend

at line 162
array|false get_word_length()

Returns the word_length array

Return Value

array|false

min and max word length for searching

at line 170
bool split_keywords(string $keywords, string $terms)

Splits keywords entered by a user into an array of words stored in $this->split_words This function fills $this->search_query with the cleaned user search query

If $terms is 'any' then the words will be extracted from the search query and combined with | inside brackets. They will afterwards be treated like an standard search query.

Then it analyses the query and fills the internal arrays $must_not_contain_ids, $must_contain_ids and $must_exclude_one_ids which are later used by keyword_search()

Parameters

string $keywords

contains the search query string as entered by the user

string $terms

is either 'all' (use search query as entered, default words to 'must be contained in post') or 'any' (find all posts containing at least one of the given words)

Return Value

bool

false if no valid keywords were found and otherwise true

Performs a search on keywords depending on display specific params. You have to run split_keywords() first

Parameters

string $type

contains either posts or topics depending on what should be searched for

string $fields

contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched)

string $terms

is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words)

array $sort_by_sql

contains SQL code for the ORDER BY part of a query

string $sort_key

is the key of $sort_by_sql for the selected sorting

string $sort_dir

is either a or d representing ASC and DESC

string $sort_days

specifies the maximum amount of days a post may be old

array $ex_fid_ary

specifies an array of forum ids which should not be searched

string $post_visibility

specifies which types of posts the user can view in which forums

int $topic_id

is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched

array $author_ary

an array of author ids if the author should be ignored during the search the array is empty

string $author_name

specifies the author match, when ANONYMOUS is also a search-match

array $id_ary

passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered

int $start

indicates the first index of the page

int $per_page

number of ids each page is supposed to contain

Return Value

bool|int

total number of results

Performs a search on an author's posts without caring about message contents. Depends on display specific params

Parameters

string $type

contains either posts or topics depending on what should be searched for

bool $firstpost_only

if true, only topic starting posts will be considered

array $sort_by_sql

contains SQL code for the ORDER BY part of a query

string $sort_key

is the key of $sort_by_sql for the selected sorting

string $sort_dir

is either a or d representing ASC and DESC

string $sort_days

specifies the maximum amount of days a post may be old

array $ex_fid_ary

specifies an array of forum ids which should not be searched

string $post_visibility

specifies which types of posts the user can view in which forums

int $topic_id

is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched

array $author_ary

an array of author ids

string $author_name

specifies the author match, when ANONYMOUS is also a search-match

array $id_ary

passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered

int $start

indicates the first index of the page

int $per_page

number of ids each page is supposed to contain

Return Value

bool|int

total number of results

Returns if phrase search is supported or not

Return Value

bool

at line 802
index(string $mode, int $post_id, string $message, string $subject, int $poster_id, int $forum_id)

Updates wordlist and wordmatch tables when a message is posted or changed Destroys cached search results, that contained one of the new words in a post so the results won't be outdated

Parameters

string $mode

contains the post mode: edit, post, reply, quote ...

int $post_id

contains the post id of the post to index

string $message

contains the post text of the post

string $subject

contains the subject of the post to index

int $poster_id

contains the user id of the poster

int $forum_id

contains the forum id of parent forum of the post

at line 850
void index_remove(array $post_ids, array $author_ids, array $forum_ids)

Destroy cached results, that might be outdated after deleting a post

Parameters

array $post_ids
array $author_ids
array $forum_ids

Return Value

void

at line 858
void tidy()

Destroy old cache entries

Return Value

void

at line 987
bool index_created()

Returns true if both FULLTEXT indexes exist

Return Value

bool

at line 1000
array|false index_stats()

Returns an associative array containing information about the indexes

Return Value

array|false

Language string of error false otherwise

at line 1015
protected get_stats()

{@inheritdoc}

at line 1060
protected array split_message(string $text)

Turns text into an array of words

Parameters

string $text

contains post text/subject

Return Value

array

at line 1085
array get_acp_options()

Display various options that can be configured for the backend from the acp

Return Value

array

array containing template and config variables