It might be because it's an empty collection. Without further testing I wouldn't know for sure. But maybe give this a try
public function prepareProductCollection($collection)
{
$collection
->addAttributeToSelect('entity_id')
->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())
->setStore(Mage::app()->getStore())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addStoreFilter()
->addUrlRewrite();
$extra_collection = Mage::getResourceModel('catalog/product_collection')
->addFieldToSelect('entity_id')
->addFieldToFilter('entity_id', array(1,2));
$collection_ids = array_merge($collection->getAllId(), $extra_collection);
$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addFieldToFilter('entity_id', $collection_ids);
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
return $this;
}
As you said, Solr and Elasticsearch are both built on top of the Apache Lucene project, so what's the difference and why would Magento deprecate support for Solr in favor of Elasticsearch?
First, if you're not familiar with these tools, they are open-source search engines. They support text search (think keywords typed into your search box) among other things. Honestly, these are serious search engines and if you are planning to manage either Solr or Elasticsearch yourself, you may want to try it first as these tools are significant pieces of infrastructure. That said, they are seriously powerful and can support more nuanced search scenarios than your default full-text search in a relational database like Postgres.
The feature set of Solr and Elasticsearch is, for practical purposes, identical. Solr really excels at some more advanced search problems and has a pretty natural extension framework. Elasticsearch favors a JSON/REST API approach rather than Solr's DSL-oriented interface (although Solr is releasing more JSON/REST APIs).
For differences, Elasticsearch is maybe a little easier to use out-of-the-box, but it's not a consumer product. In fact, the simple starting cases with Elasticsearch can lead to later difficulties for newbies who may not appreciate what they're getting into. For single server instances, I would say they're roughly equivalent.
As to why Magento is pushing Elasticsearch over Solr, I think Elasticsearch's JSON interface is a little easier to learn quickly, and its deployment story requires less operational skill than Solr.
In either case, if you're considering a different search engine for Magento you should consider some of the managed services for Elasticsearch (or Solr) rather than managing the servers yourself, as that is a whole skill in itself.
Best Answer
By default magento doesn't use wildcards (
*123.5N*
) with ES. Query building logic implemented in classMagento\Elasticsearch\SearchAdapter\Query\Builder\Query
(need change query type toquery_string
).