If you are referring to the product created_at
and updated_at
attributes, then simply commenting out the ->addVisibleFilter()
in the Catalog Product Attribute Grid in the admin and simply set the Search and Sort fields to Yes, and re-index, you'll notice the date(s) are now in the catalogsearch_fulltext
table which the Enterprise Solr will recognize and add the data to its doc records as well.
NOTE: Don't forgot to remove the core code change or do it via local code pool obviously if you like.
class Mage_Adminhtml_Block_Catalog_Product_Attribute_Grid extends Mage_Eav_Block_Adminhtml_Attribute_Grid_Abstract
{
/**
* Prepare product attributes grid collection object
*
* @return Mage_Adminhtml_Block_Catalog_Product_Attribute_Grid
*/
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('catalog/product_attribute_collection');
//->addVisibleFilter();
$this->setCollection($collection);
return parent::_prepareCollection();
}
After this you'll want to let Solr know its a sortable metadata field.
Enterprise/Search/Model/Adapter/Abstract.php you'll notice:
/**
* Store common Solr metadata fields
* All fields, that come up from search engine will be filtered by these keys
*
* @var array
*/
protected $_usedFields = array('sku', 'visibility', 'in_stock');
You may want to also look over the method: _prepareIndexProductData
in
Enterprise/Search/Model/Adapter/Abstract.php
/**
* Prepare index data for using in search engine metadata.
* Prepare fields for advanced search, navigation, sorting and fulltext fields for each search weight for
* quick search and spell.
*
* @param array $productIndexData
* @param int $productId
* @param int $storeId
*
* @return array|bool
*/
protected function _prepareIndexProductData($productIndexData, $productId, $storeId)
I've only tested the ability to edit the "non-visible" attributes and confirmed the addition to the fulltext table, I don't have Solr running locally at the moment to test it, but in theory should work without any need to mirror redundant data.
Hope this helps!
You can just add 2 product attributes with the names you want and make them available for sorting.
If you need a custom logic behind it rewrite the method Mage_Catalog_Model_Resource_Product_Collection::addAttributeToSort
and add your own case
section to handle your attributes.
Here is an example on how it's done for created_at
. You can do something similar for your attributes.
Best Answer
you cannot modify the attribute
created_at
in the backend.So you need to create a module that just activates the
created_at
attribute for sorting.For this you will need the following files:
app/etc/modules/[Namespace]_[Module].xml
- the declaration fileapp/code/local/[Namespace]/[Module]/etc/config.xml
- the configuration fileapp/code/local/[Namespace]/[Module]/sql/[namespace]_[module]_setup/install-1.0.0.php
- the install scriptClear the cache and refresh any page. Now you should have the
Date Added
(created_at
) attribute available for sorting in any category.