Home >Backend Development >PHP Tutorial >The anatomy of smart search in Joomla art Introduction.
You probably already know Joomla has built-in search functionality, which meets modern requirements - the smart search component. But what if your users need a little more? What if you want third party extensions to be searchable as well? In this series of articles, we will look at how to create a smart search plugin for a third-party Joomla component.
Historically, there were 2 search components in the Joomla core: just "search" and "smart search". A simple search was included in Joomla 1.x and has not changed significantly since then. In order for this component (com_search) to search not only in the core components, it was necessary to write a plugin, the essence of which was mainly to give the component the necessary SQL query and form an object of a structure understandable to the component from the query results. The search itself was essentially an SQL query to the database with LIKE '%word%'. There have also been cases when the Sphinx search engine in Joomla was used with the help of a simple search plugin.
Starting with Joomla 2.5, the Smart search component, com_finder, was included in the core, the main difference between which and simple search was content indexing. The search itself began to produce results based on the relevance of the content. For the site user, search parameters have appeared that allow you to limit the results using filters based on various parameters: the start and end date of publication, language, type (article, category, product, etc.), specific category, author. Under the hood, the text is divided into tokens, weight is calculated for tokens, etc. Indexing settings are available in the component settings.
An example from the Joomla smart search hint for site visitors:
Entering this and that into the search form will return results containing both "this" and "that".
Entering this not that into the search form will return results containing "this" and not "that".
Entering this or that into the search form will return results containing either "this" or "that".
Entering "this and that" (with quotes) into the search form will return results containing the exact phrase "this and that".
I would like to note once again that this is the functionality of the Joomla core, not a third-party extension and not some kind of third-party, usually paid, service.
In practice, I have come across the fact that site visitors usually do not use all these additional filters and search parameters, but rather ask again to clarify the query. On a regular site with articles, search parameters are unlikely to be in demand, but in an internal closed help system or documentation system (Joomla has versioning of articles and Workflows, see details on docs.joomla.org) these parameters would be more in demand.
The index of your mini-google needs to be updated periodically, since something is constantly changing on the live site: products and articles are added, archived, deleted, contacts are updated, etc. In order for the user to receive up-to-date data in the search, you need to regularly reindex the content. The index results are stored in the database, which is why it increases in size. This is normal for this search implementation.
You can start indexing manually from the admin panel
Or (this is the preferred option) using the Joomla CLI server command line. To do this, go to the cli folder of your site (how to work with Joomla CLI for more information, see the article Joomla 4: A Powerful CLI Application).
CLI folder in Joomla.
In this folder, run the command:
php joomla.php finder:index
And Joomla indexes your content pretty quickly.
Indexing by smart search in Joomla 5 via the CLI.
We add this command to CRON for scheduled execution and site visitors will be happy to see the current search results.
0 2 * * * php /path/to/site/public_html/cli/joomla.php finder:index >/dev/null 2>&l
Joomla user fields are used for a wide variety of types of sites, often for catalogs of services or goods where online payment and calculation of delivery on the site are not required. In order for Joomla to search by the values of these fields, you need to specify the "Search Index" parameter for each field (the "Options" tab, at the very bottom):
You can also see the article Adding custom fields in the results of Smart Search and JFilters, which describes how to display field values in search results using layout override.
A taxonomy is a way to display field data in search results, for example, "Category: Any category", "Author: Any author." The taxonomy can be nested. To search by field value, select the "Make searchable" or "Make searchable and add as taxonomy" options.
A taxonomy example in Joomla smart search.
In the next article, we will look at how to create a smart search plugin for a Joomla component using the example of JoomShopping. We will start to encounter nuances and details that could hinder us, but in the end we will overcome all difficulties and create a working smart search plugin for Joomla 5.
The above is the detailed content of The anatomy of smart search in Joomla art Introduction.. For more information, please follow other related articles on the PHP Chinese website!