Description of the Plugin’s Core Components
The WP Fast Total Search (WPFTS) plugin consists of four main components:
-
Indexer: Responsible for creating and updating the search index. It extracts data from posts, pages, custom post types, and other sources, processes it according to indexing rules, and saves it to the database. The indexer works in the background and can be run manually or on a schedule. Key class:
WPFTS_Index
. -
Search Engine: Responsible for processing search queries and finding relevant results. It uses data from the search index for fast searching and calculates the relevance of results based on cluster weights and other parameters. Key class:
WPFTS_Search
. -
Widget: The
WPFTS :: Live Search
widget provides a user interface for searching on the website’s frontend. It supports autocomplete and allows users to quickly find the information they need. Key class:WPFTS_Custom_Widget
. There is also a shortcode[wpfts_widget]
, which allows embedding the widget anywhere on a page. -
Smart Excerpts Generator: This component is responsible for creating “Smart Excerpts”—interactive text snippets displayed in search results. Smart Excerpts contain found keywords in context and allow users to quickly assess the relevance of results. They also provide more convenient navigation through the found documents. Key class:
WPFTS_Result_Item
.
Indexer
The WPFTS Indexer is a critical component responsible for creating and updating the search index. It performs the following actions:
-
Data Extraction: The indexer extracts data from various sources, such as posts, pages, custom post types, meta-fields, taxonomies, etc.
-
Data Processing: The extracted data is processed according to indexing rules. This may include removing HTML tags, converting special characters, converting text to lowercase, and other transformations.
-
Tokenization: The processed text is split into individual words (tokens).
-
Index Creation: The indexer creates an index containing information about which posts and clusters contain which words.
-
Index Saving: The created index is saved to the database in an optimized format for fast searching.
Search Engine
The WPFTS Search Engine is responsible for processing search queries and finding relevant results. It performs the following actions:
-
Query Analysis: The engine analyzes the search query, splitting it into individual terms.
-
Index Search: The engine uses the index to quickly find posts containing the specified terms.
-
Relevance Calculation: The relevance is calculated for each found post based on cluster weights, term frequency, and other parameters.
-
Result Sorting: Search results are sorted by relevance or other parameters specified in the query.
Widget
The WPFTS :: Live Search
widget provides a user interface for searching on the website’s frontend. It features:
-
Autocomplete: The widget supports autocomplete of search queries, helping users find the information they need faster.
-
Customizable Appearance: You can customize the widget’s appearance using CSS.
-
WPFTS Integration: The widget uses the WPFTS search engine to execute queries.
-
Shortcode Support: The widget is also available as a shortcode
[wpfts_widget]
, allowing it to be embedded anywhere on a page.
Smart Excerpts Generator
The Smart Excerpts Generator performs the following actions:
-
Data Extraction: The component extracts indexed post data, including content, metadata, and other data defined by indexing rules. This is done using the
WPFTS_Core::getPostChunks()
method. -
Relevant Sentence Selection: Based on the search query, the generator selects the most relevant sentences from the post text. This uses the
WPFTS_TokenCollector
class and itsGetMostPowerful()
andGetOrderedByLessDistance()
methods. -
Excerpt Formation: The selected sentences are combined into an excerpt, with found words and phrases highlighted using the
<b>
tag. -
Link and Style Addition: Links leading to the post page with a highlighted fragment can be added to each sentence and/or word. Sentence styles are defined in the plugin settings and can be modified using the
wpfts_get_sentence_styles
filter. HTML code is generated by theWPFTS_Result_Item::applySentenceStyles()
method. -
Unfound Word Handling: If not all words from the search query were found in the post text, they may be displayed in the Smart Excerpt with a strikethrough, so the user can see which words were not considered during the search.
-
Metadata Addition: Additional information, such as relevance, file size (for attachments), and a download link, can be added to the Smart Excerpt.
-
Filtering and Output: Before outputting to the search results page, the Smart Excerpt can be modified using the
wpfts_se_data
andwpfts_se_output
filters.
Interactivity and Navigation
Smart Excerpts in WPFTS are interactive. Clicking on a highlighted word or phrase in the excerpt takes the user to the post page, where WPFTS highlights the corresponding fragment in the text and scrolls the page to it. This provides more convenient navigation through search results and helps users quickly find the necessary information in the post text. This functionality is implemented using JavaScript.
The interaction of these components ensures fast, relevant, and convenient search on your WordPress website.