I want to understand the logic or algorithm behind the search functionality in Magento Connect when the Sort by option in Refine search is set to sort by Relavence
2 Answers
I would suppose that search is implemented using MySQL FULLTEXT index.
Here is a quote from MySQL official documentation regarding to how that index works:
Rows returned are automatically sorted with the highest relevance first. Relevance values are nonnegative floating-point numbers. Zero relevance means no similarity. Relevance is computed based on the number of words in the row, the number of unique words in that row, the total number of words in the collection, and the number of documents (rows) that contain a particular word.
As a proof of that you can try to perform a search on Magento Connect website using the following search terms:
- Slider
- Order
- SEO
For the first term the first results are modules with titles:
- I-Slider - Banner Slider
- Product Slider Pro | Multiple Sliders | Responsive Slider
For the second:
- Order - Order Reminder
For the last one:
- SEO ― Advanced SEO Suite
As you can see in all cases the first items have more than one occurrence of search term in the title so relevance of them is higher.
Seems like that is how Magento Connect search works.
-
Not a bad guess, Alex. Though I suppose it assumes connect is built on top of the same underlying stack as Magento, which may not be the case. Hoping @BenMarks chimes in Commented Aug 24, 2015 at 16:10
While Magento.com is built upon Drupal, Magento Connect seems to be using Magento itself, at least as foundation.
Evidence:
- the search URL
magento-connect/catalogsearch/result/?q=TERM
the used JavaScript files:
paths to CSS files such as http://www.magentocommerce.com/magento-connect/skin/frontend/enterprise/connect/css/base.css with license the header containing:
* @category design * @package enterprise_connect * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com) * @license http://www.magentocommerce.com/license/enterprise-edition
With this information, we can concur that the search works the same way as in Magento Enterprise. Now there are several possibilities:
- MySQL LIKE search
- MySQL FULLTEXT search
- MySQL combined search
- Solr
As you can see if you search for arbitrary search term combinations, it's not the default LIKE
search with OR
that everybody hates. So either it's the fulltext search that orders by relevance by default, as suggested by @alex_b or the Solr search of the Enterprise_Search module, for which I probably am not allowed to disclose details.