Component Interaction
The WP Fast Total Search (WPFTS)
components interact to provide fast and relevant search results. Here’s how they work together:
-
Indexer and Database: The indexer (
WPFTS_Index
) retrieves data from WordPress (posts, pages, meta-fields, etc.), processes it, and stores it in the database in an optimized format. It uses theWPFTS_Database
class to interact with the database and theWPFTS_DB
class for handling MySQLi errors. Data is stored in several tables, the structure of which will be described in the next section. The indexer is called when the plugin is activated, when posts are saved or deleted (save_post
andafter_delete_post
hooks), and also on a cron schedule (wpfts_indexer_event
hook). -
Search Engine and Database: When a user performs a search, the search engine (
WPFTS_Search
) receives the search query and uses the index stored in the database to quickly find relevant posts. It also uses theWPFTS_DB
class to interact with the database. The engine calculates the relevance of the results and sorts them according to the settings. Interaction with WordPress occurs through thepre_get_posts
,posts_search
,posts_join
,posts_search_orderby
hooks, and others. -
Search Engine and Smart Excerpts Generator: After the search engine finds relevant posts, the Smart Excerpts generator (
WPFTS_Result_Item
) creates excerpts containing the found keywords. The engine passes the necessary data about the posts and the search query to the generator. The generator uses various filters (e.g.,wpfts_get_sentence_styles
,wpfts_se_data
,wpfts_se_output
) to customize the appearance of the excerpts. -
Widget and Search Engine: The Live Search widget (
WPFTS_Custom_Widget
) provides a user interface for searching. When a user enters a query, the widget sends it to the search engine via AJAX (wp_ajax_nopriv_wpfts_autocomplete
andwp_ajax_wpfts_autocomplete
hooks). The engine returns the search results, which are displayed in the widget. -
Fire & Flare: The
Fire & Flare
microservice is used for fast synchronization between the server and the client side (e.g., to display the indexing status in real time). The Fire component on the server sends short data packets to the Flare component on the client at regular intervals. TheWPFTS_Flare
class is responsible for sending data on the server, and the JavaScript code on the client processes the received data.
Interaction Diagram
[User] --> [Widget] --AJAX--> [Search Engine] --> [Database]
^
|
+--- [Smart Excerpts Generator]
[Cron] --> [Indexer] --> [Database]
[WordPress (save_post, after_delete_post)] --> [Indexer] --> [Database]
[Fire (server)] --HTTP--> [Flare (client)]
Additional Notes
-
WPFTS uses transients to store temporary data, such as the indexing status.
-
Semaphores (WPFTS_Semaphore class) are used to synchronize processes and prevent conflicts.
-
The plugin provides developers with many filters to modify the behavior of components and their interaction.
Understanding the interaction of WPFTS components will help addon developers effectively integrate their code with the plugin and extend its functionality.