Magento CatalogSearch Model Problem - Unable to use loadByQueryText();
You are able to tell Magento with field to use on load. The following code should allow you to tell catalogsearch/query to load by the query_text attribute.
$querymodel = Mage::getModel('catalogsearch/query');
$querymodel->load('test 123','query_text');
I've done the following in order to debug:
$querymodel = Mage::getModel('catalogsearch/query');
$querymodel->loadByQueryText('test');
$data = $querymodel->getData();
print_r($querymodel->getData());
And if the record exists, the output is:
Array
(
[query_id] => 54120
[query_text] => test
[num_results] => 1
[popularity] => 1
[redirect] =>
[synonym_for] =>
[store_id] => 6
[display_in_terms] => 1
[is_active] => 1
[is_processed] => 0
[updated_at] => 2013-01-08 03:55:26
)
In your code if (!$querymodel->getId()) {
should be if (!$querymodel->getQueryId()) {
or look at the value returned by $querymodel->getData()
I ended up getting it working in a less clean way - no idea why the loadByQueryText() method is stuill not working.
$querymodel = Mage::getModel('catalogsearch/query')
->getCollection()
->addFieldToFilter('query_text', 'testing 123')
->getFirstItem();
This returns a result so I'm gonna use it.