title: Rewriting AutoSuggest (Minisearch) of Magento
body: <p>I been trying for hours now to successfully rewrite Magento's build-in Autosuggest Function so it displays productnames instead of query history entries. I want nothing fancy, no product pictures and whatnot, just plain product name suggestions.</p>
  
  <p>So to get the productnames, I created under <code>app/code/local/Aw</code> the folder <code>CatalogSearch/Model</code> and there created a file named <code>Query.php</code>. Inside that file I have the following class and rewritten method:</p>
  
  <pre><code>class Aw_CatalogSearch_Model_Query 
      extends Mage_CatalogSearch_Model_Query {
  
      public function getSuggestCollection() {
          $collection = $this-&gt;getData('suggest_collection');
          if (is_null($collection)) {
              $collection = Mage::getModel('catalog/product');
              Mage::getSingleton('catalog/product_status')
                  -&gt;addVisibleFilterToCollection($collection);
              $collection-&gt;getCollection()
                  -&gt;addAttributeToSelect('name')
                  -&gt;addAttributeToFilter('name', array('like' =&gt;         
                      '%'.$this-&gt;getQueryText().'%'))
                  -&gt;addExpressionAttributeToSelect('query_text', '{{name}}', 'name')
                  -&gt;addAttributeToSort('name', 'ASC')
                  -&gt;setPageSize(10)
                  -&gt;addStoreFilter($this-&gt;getStoreId());
              $this-&gt;setData('suggest_collection', $collection);
          }
          return $collection;
      }
  };
  </code></pre>
  
  <p>I created the module xml file in app/etc/modules/ and the module configuration in <code>app/code/local/Aw/CatalogSearch/etc/config.xml</code></p>
  
  <p>All good so far, the overwritten method <code>getSuggestCollection()</code> is executed.</p>
  
  <p>The problem comes in <code>app/code/core/Mage/CatalogSearch/Block/Autocomplete.php</code>, in the <code>getSuggestData()</code> method. </p>
  
  <pre><code>public function getSuggestData()
  {
      if (!$this-&gt;_suggestData) {
          $collection = $this-&gt;helper('catalogsearch')-&gt;getSuggestCollection();
          $query = $this-&gt;helper('catalogsearch')-&gt;getQueryText();
          $counter = 0;
          $data = array();
          foreach ($collection as $item) {
              $_data = array(
                  'title' =&gt; $item-&gt;getQueryText(),
                  'row_class' =&gt; (++$counter)%2?'odd':'even',
                  'num_of_results' =&gt; $item-&gt;getNumResults()
              );
  
              if ($item-&gt;getQueryText() == $query) {
                  array_unshift($data, $_data);
              }
              else {
                  $data[] = $_data;
              }
          }
          $this-&gt;_suggestData = $data;
      }
      return $this-&gt;_suggestData;
  }
  </code></pre>
  
  <p>When it iterates over the collection, I get a </p>
  
  <pre><code>Call to a member function getQueryText() on a non-object ...
  </code></pre>
  
  <p>The point I do not understand is that I have defined an alias field named 'query_text' in the collection query inside the <code>getSuggestCollection()</code> method. Even when I used something like <code>getData('query_text')</code> or <code>$item-&gt;getQuery_text()</code> to get the data of this field is not working. 
  I have the strong feeling, that the collection object is not valid as it supposed be within the getSuggestData() method of <code>Mage_CatalogSearch_Block_Autocomplete</code> class.</p>
  
  <p>Can anybody point me out how to solve this issue? Is it not possible as above way to gather suggestions from the products collection and pass these to Autocomplete.php?</p>
  
  <p>This is my first magento project, so please bear with me! I am really lost on this one!</p>
  
  <p>Any hint is greatly apprecitated.</p>
  
  <p>Using Magento 1.7.0.2 for this project.</p>