Magento - sort/order the suggestions in the Autocomplete search form

how can I change the sort/order in the suggestions of the Autocomplete search form.

I use Magento version 1.4.1.1

Thanks for help.

-------------Problems Reply------------

To make it quick, copy /app/code/core/Mage/CatalogSearch/Model/Mysql4/Query/Collection.php into /app/code/local/Mage/CatalogSearch/Model/Mysql4/Query/Collection.php in local scope file find this line:

->order('popularity desc');

and replace it with this:

->order('query_text asc');

This is enough to make it work.

If you are interested in how does it work here you go.

  1. form.mini.phtml sends request to suggestAction function of Mage_CatalogSearch_AjaxController though the following url: http://www.yourdomain.com/catalogsearch/ajax/suggest?q=query (may be quite useful for debugging).
  2. Then instance of Mage_CatalogSearch_Block_Autocomplete makes a query to database catalogsearch_query table through getSuggestCollection function call.
  3. Inside this function the actual collection is built but for some reasons I was not able to apply to setOrder function to it so I had to dug one step deeper.
  4. The clue lies in setQueryFilter function from the file you just copied above. Replacing the ordering method did the trick.

Hope it helped.

Category:magento Views:0 Time:2011-06-10
Tags: magento

Related post

  • Google Suggest - What determines the sort order of suggested queries on google? 2010-04-15

    How is this sort order determined? Is it ranked by popularity, number of results, or a mysterious google algorithm? Does there algorithm take into account the search popularity of a query (using google-trends data or something)? Edit: I found a news

  • set initial sort order in Silverlight DataGrid? 2008-10-22

    When I first load data into a Silverlight DataGrid control, how can I make the screen look exactly as if the user had just clicked the header of the first column? In other words, the data should be sorted in ascending order according to that column's

  • Rails 3 fields_for - sort order gets lost 2011-02-10

    I am using Rails 3.0.3 with ruby 1.9.2p0. In my profiles_controller (edit function) I have this call @profile = Profile.find(params[:id]) @profile_items = @profile.profile_items.order("pos") to get the @profile_items in the correct order, sorted on "

  • Magento - change Sort order to Name in Search Result 2011-06-10

    how can change Sort order to Name in Magento Search Result page? Thanks for help. --------------Solutions------------- Add &order=name to your query string. In order to do it go to /app/design/frontend/{your-interface}/{your-theme}/template/catal

  • Changing the new product widget sort order in Magento 2011-11-29

    I'm using Magento for my webshop and my homepage uses a new products widget. I want to change the sort order for the products within the widget. I searched for hours but I can't figure it out. --------------Solutions------------- The block for displa

  • Add sort order to featured products in magento 2012-03-17

    I am using the following piece of code to allow users to set featured products that will display on the homepage but I need to extend this so that they can also dictate the sort order of the items. By default it displays the producst in the order the

  • Change sort order of sub categories in magento 2012-03-18

    I have some code that calls the sub categories of a main category and I need to be able to change the sort order of teh sub categories on the front end of the site. I have tried adding the attribute to sort tag but this isnt doing anything. Can anyon

  • Maintaining sort order of database table rows 2008-12-29

    Say I have at database table containing information about a news article in each row. The table has an integer "sort" column to dictate the order in which the articles are to be presented on a web site. How do I best implement and maintain this sort

  • Auto Generate Sort Orders with SQL UPDATE 2009-02-04

    I recently imported about 60k records into a table that relates data in one table to data in another table. However, my client has since requested that a sort order be added to all 60k records. My hope is there is a nice clean way to auto generate th

  • Recursive SQL CTE's and Custom Sort Ordering 2009-02-19

    Image you are creating a DB schema for a threaded discussion board. Is there an efficient way to select a properly sorted list for a given thread? The code I have written works but does not sort the way I would like it too. Let's say you have this da

  • Best Way of Having End User Specify Sort Order in Rails 2009-04-06

    I am looking for a suggestion on the best way of having an end user from a Rails application's view files set the sort order of a result set returned by a model's "find" method. In other words I would like a user to be able to choose their sort order

  • DB Design: Sort Order for Lookup Tables 2009-05-03

    I have an application where the database back-end has around 15 lookup tables. For instance there is a table for Counties like this: CountyID(PK) County 49001 Beaver 49005 Cache 49007 Carbon 49009 Daggett 49011 Davis 49015 Emery 49029 Morgan 49031 Pi

  • Controlling the sort order of a list from an admin UI 2009-05-07

    I have a list of data that users are able to control the sort order of. It looks something like this Apples /\ \/ Oranges /\ \/ pears /\ \/ banana /\ \/ Pineapples /\ \/ etc /\ \/ the /\ and \/ are meant to be up and down arrows When the user clicks

  • How to get RedGate Data Compare to consider sort order? 2009-05-13

    I am using SQL-Server 2005. I have a dev and prod database that have essentially the same data in them. When I do a compare with RedGate SQL Data Compare 5, it says that only 4 records differ. However, when I open up the tables and view them, they ar

  • Iterate over a Javascript associative array in sorted order 2009-05-20

    Let's say I have a Javascript associative array (a.k.a. hash, a.k.a. dictionary): var a = new Array(); a['b'] = 1; a['z'] = 1; a['a'] = 1; How can I iterate over the keys in sorted order? If it helps simplify things, I don't even need the values (the

  • Are there settings in Crystal Reports that modify sort order of data sources? 2009-12-03

    I'm working with Crystal Reports in VB.NET in Visual Studio 2005. I have a List(Of Stuff) that I've sorted according to one of the object's members. I've verified in the debugger that the list is sorted correctly. When I define my list as the data so

  • Android: AutoCompleteTextView - how to customize sort order 2010-01-22

    The normal way how AutoCompleteTextView shows suggestions, is that it shows only strings that begin with the text the user entered, but the sort order of the results is undefined. Can I somehow sort them by myself? So that when user enters e.g. "g",

  • Magento - Sort by Date Added 2010-02-10

    How can I make Magento sort products in the catalog by the date they were added? This isn't an option in the admin so guessing it needs to be done in the code somewhere. Thanks. --------------Solutions------------- It is quite easy to add a sorting b

  • SQL Primary key sort order 2010-09-03

    I am using MS SQL server 2005 I have a table with 3 columns where I store user-message mapping like: msg_for msg_from msg_id bob bob 1 bob john 1 bob steve 1 bob bob 2 bob john 2 bob bob 3 bob john 3 bob steve 3 The PK is on 3 columns and msg_id is F

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.149 (s). 11 q(s)