What is the equivalent function in magento 2.
public function execute() //method name changed to execute() as per core
{
//echo 'result controller';die;
//Custom Change
$params = $this->getRequest()->getParams();
$response = array();
//Custom Change End
//$query = Mage::helper('catalogsearch')->getQuery();
$this->_objectManager->get('Magento\CatalogSearch\Helper\Data')->checkNotes();
$this->layerResolver->create(Resolver::CATALOG_LAYER_SEARCH);
$query = $this->_queryFactory->get();
/* @var $query Mage_CatalogSearch_Model_Query */
//$query->setStoreId(Mage::app()->getStore()->getId());
$query->setStoreId($this->_storeManager->getStore()->getId());
if ($query->getQueryText() != '')
{
//if (Mage::helper('catalogsearch')->isMinQueryLength()) {
if ($this->_objectManager->get('Magento\Search\Helper\Data')->isMinQueryLength())
{
$query->setId(0)
->setIsActive(1)
->setIsProcessed(1);
}
else {
if ($query->getId()) {
$query->setPopularity($query->getPopularity()+1);
}
else {
$query->setPopularity(1);
}
if ($query->getRedirect()){
$query->save();
$this->getResponse()->setRedirect($query->getRedirect());
return;
}
else {
$query->prepare();
}
}
//Mage::helper('catalogsearch')->checkNotes();
$this->_objectManager->get('Magento\Search\Helper\Data')->checkNotes();
//$this->loadLayout();
$this->_view->loadLayout();
$this->_view->renderLayout();
//Custom change
if(false && $this->getRequest()->isXmlHttpRequest())
{ //Check if it was an AJAX request
$viewpanel = $this->getLayout()->getBlock('catalogsearch.leftnav')->toHtml(); //Get the new Layered Menu
$productlist = $this->getLayout()->getBlock('product_searchlist_toolbar')->toHtml(); //New product List
$response['status'] = 'SUCCESS'; //Send Success
$response['viewpanel']=$viewpanel;
$response['productlist'] = $productlist;
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
return;
}//End custom search
//$this->_initLayoutMessages('catalog/session');
//$this->_initLayoutMessages('checkout/session');
//$this->renderLayout();
/* if (!Mage::helper('catalogsearch')->isMinQueryLength()) {
$query->save();
} */
if (!$this->_objectManager->get('Magento\Search\Helper\Data')->isMinQueryLength()) {
$query->save();
}
}
else {
//$this->_redirectReferer();
$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
}
}
Like for eg: there is no getQuery() in magento 2 catalog search helper. i want the equivalent functions for the same in magento2
\Magento\Search\Model\QueryFactory
and get query with$this->queryFactory->get()->getQueryText();
$query
contains a string. Please update your question with your actual code that produces the error, and the full error message.