class fulltext_sphinx implements search_backend_interface

Fulltext search based on the sphinx search daemon

Constants

protected SPHINX_MAX_MATCHES

protected SPHINX_CONNECT_RETRIES

protected SPHINX_CONNECT_WAIT_TIME

Properties

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 $id

Holds unique sphinx id

protected string $indexes

Stores the names of both main and delta sphinx indexes separated by a semicolon

protected SphinxClient $sphinx

Sphinx search client object

protected string $phpbb_root_path

Relative path to board root

protected string $php_ext

PHP Extension

protected auth $auth

Auth object

protected config $config

Config object

protected driver_interface $db

Database connection

protected tools_interface $db_tools

Database Tools object

protected string $dbtype

Stores the database type if supported by sphinx

protected dispatcher_interface $phpbb_dispatcher

phpBB event dispatcher object

protected language $language
protected log $log
protected user $user

User object

protected string $config_file_data

Stores the generated content of the sphinx config file

protected string $search_query

Contains tidied search query.

Methods

__construct(auth $auth, config $config, driver_interface $db, tools_interface $db_tools, dispatcher_interface $phpbb_dispatcher, language $language, log $log, user $user, string $phpbb_root_path, string $phpEx)

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

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()

Nothing needs to be destroyed

array|null
create_index(int $post_counter = 0)

Create fulltext index

array|null
delete_index(int $post_counter = null)

Drop fulltext index

bool
index_created($allow_new_files = true)

Returns true if both FULLTEXT indexes exist

array|false
index_stats()

Returns an associative array containing information about the indexes

get_stats()

Computes the stats and store them in the $this->stats associative array

string
sphinx_clean_search_string(string $search_string)

Cleans search query passed into Sphinx search engine, as follows:

  1. Hyphenated words are replaced with keyword search for either the exact phrase with spaces or as a single word without spaces eg search for "know-it-all" becomes ("know it all"|"knowitall*")
  2. Words with apostrophes are contracted eg "it's" becomes "its"
  3. <, >, " and & are decoded from HTML entities.

array
get_acp_options()

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

bool
config_generate()

Generates content of sphinx.conf

string
get_type()

Gets backend class

Details

at line 157
__construct(auth $auth, config $config, driver_interface $db, tools_interface $db_tools, dispatcher_interface $phpbb_dispatcher, language $language, log $log, 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

auth $auth

Auth object

config $config

Config object

driver_interface $db

Database object

tools_interface $db_tools
dispatcher_interface $phpbb_dispatcher

Event dispatcher object

language $language
log $log
user $user

User object

string $phpbb_root_path

Relative path to phpBB root

string $phpEx

PHP file extension

at line 193
string get_name()

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

Return Value

string

Name

at line 201
bool is_available()

Returns if the search engine is available

Return Value

bool

at line 209
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 225
string get_search_query()

Returns the search_query

Return Value

string

search query

at line 233
array get_common_words()

Returns the common_words array

Return Value

array

common words that are ignored by search backend

at line 241
array|false get_word_length()

Returns the word_length array

Return Value

array|false

min and max word length for searching

at line 249
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 544
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 610
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 624
void tidy()

Nothing needs to be destroyed

Return Value

void

at line 632
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 659
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

at line 672
bool index_created($allow_new_files = true)

Returns true if both FULLTEXT indexes exist

Parameters

$allow_new_files

Return Value

bool

at line 687
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 704
protected get_stats()

Computes the stats and store them in the $this->stats associative array

at line 754
protected string sphinx_clean_search_string(string $search_string)

Cleans search query passed into Sphinx search engine, as follows:

  1. Hyphenated words are replaced with keyword search for either the exact phrase with spaces or as a single word without spaces eg search for "know-it-all" becomes ("know it all"|"knowitall*")
  2. Words with apostrophes are contracted eg "it's" becomes "its"
  3. <, >, " and & are decoded from HTML entities.

  1. Following special characters used as search operators in Sphinx are preserved when used with correct syntax: (a) quorum matching: "the world is a wonderful place"/3 Finds 3 of the words within the phrase. Number must be between 1 and 9. (b) proximity search: "hello world"~10 Finds hello and world within 10 words of each other. Number can be between 1 and 99. (c) strict word order: aaa << bbb << ccc Finds "aaa" only where it appears before "bbb" and only where "bbb" appears before "ccc". (d) exact match operator: if lemmatizer or stemming enabled, search will find exact match only and ignore other grammatical forms of the same word stem. eg. raining =cats and =dogs will not return "raining cat and dog" eg. ="search this exact phrase" will not return "searched this exact phrase", "searching these exact phrases".
  2. Special characters /, ~, << and = not complying with the correct syntax and other reserved operators are escaped and searched literally. Special characters not explicitly listed in charset_table or blend_chars in sphinx.conf will not be indexed and keywords containing them will be ignored by Sphinx. By default, only $, %, & and @ characters are indexed and searchable. String transformation is in backend only and not visible to the end user nor reflected in the results page URL or keyword highlighting.

Parameters

string $search_string

Return Value

string

at line 783
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

at line 828
protected bool config_generate()

Generates content of sphinx.conf

Return Value

bool

True if sphinx.conf content is correctly generated, false otherwise

at line 1026
string get_type()

Gets backend class

Return Value

string