According to Econsultancy reports, up to 30% of online customers decide to use an internal search engine within an e-commerce website to find a specific offer. Now, by improving search results the customers see, the store owners can increase conversion rates and make a bigger profit.
From the programming point of view, however, building a search engine that displays the results as accurately matched to the phrase as Google, with recognition of typos in phrases and detection of synonyms included, is quite a challenge. Fortunately, there are search engines, such as Sphinx, Solr, or Elasticsearch, designed to perform smart and accurate searches for your customers’ shopping pleasure.
Search functionality in Magento
By default, Magento supports three search types: Like, Full-text, and a combination of both. The business logic/sql queries for default search in Magento can be found in the following file: app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php.
All these methods operate in catalogsearch_fulltext table which is filled with product data during Catalog Search Index processing. Each type influences the SQL query made during the first phrase search in the front-end, while the result is saved/cached in the catalogsearch_result table:
- LIKE—simple search of records with at least one word from the whole phrase
- FULLTEXT—searching the whole phrase in data_index column and sorting the results based on relevance
- Combine (Like and Full-text)—searching for records containing at least one word from the whole phrase and sorting the results based on relevance for the MATCH… AGAINST… query
Full-text search depends on numerous MySQL database configurations. For instance, ft_min_word_len is responsible for the minimum length of a search phrase, e.g. the word “BMW” can be ignored by default and not return any results, while nnodb_ft_enable_stopword, for example, can turn the list of ignored words on or off.
Elasticsearch is a search engine built on Lucene with communication interface based on HTTP and JSON documents. In other words, it’s a distributed full-text NoSQL database allowing you to create advanced search logic in your online store.
Did you mean?
Elasticsearch supports Suggesters—function responsible for suggesting a phrase that looks similar to the one you’re searching for. Suggestions can be shown with Term Suggester for single words or Phrase Suggester for whole corrected phrases.
Fuzzy Query is yet another interesting and useful function—it displays search results with phrases closest to the searched ones. Thanks to fuzziness attribute you can decide what is the maximum acceptable Levenshtein distance (the lowest number of simple actions changing one word into another—inserting a new character, deleting, or changing a character).
Elasticsearch also offers aggregations—a highly effective solution to optimizing Magento performance. Aggregations allow you to get all of the necessary information as a direct result of a searched phrase. You don’t have to make any additional queries to group all the data—accurately made query and buckets are enough.
Layered Navigation, a part of Magento which allows customer to filter list of products using selected attributes, is one of the most difficult functionalities for a database to handle. The difficulty comes from the requirement to download a list of values of attributes available for the narrowed list of products (sql queries with multiple joins and need to execute each attribute separately, multiple times.) Moreover, you often would like to display number of available products, e.g. number of products in a specific color (red shoes) or from a specific brand (Nike shoes), which generates many complicated queries in the database.
Want to improve the search position of your new or popular products? With Elasticsearch it’s a walk in a park—you can create your own functions for assessing every document and then use them for your search. Another useful tool here is function_score which enables you to change the value of every searched product and thus alter the position of every record.
As you can see, Elasticsearch has plenty of useful functions. To see its capabilities yourself, I encourage you to try and give it a go on your e-commerce website. If you are still in doubt,check who else uses Elastic services. I guarantee you’ll be positively surprised. In my next article, I’ll show you more examples of effective Elasticseach implementations in Magento so that you can make the shopping experience for your customers as smooth as possible.
On-demand webinar: Moving Forward From Legacy Systems
We’ll walk you through how to think about an upgrade, refactor, or migration project to your codebase. By the end of this webinar, you’ll have a step-by-step plan to move away from the legacy system.
Latest blog posts
Ready to talk about your project?
Tell us more
Fill out a quick form describing your needs. You can always add details later on and we’ll reply within a day!
We go through recommended tools, technologies and frameworks that best fit the challenges you face.
Once we arrange the formalities, you can meet your Polcode team members and we’ll begin developing your next project.