Bug 607894 - Tab matches always appear before normal history results.
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 09 Dec 2010 12:17:17 +0100
changeset 59384 e88c33f1fc0bc4a88f19b5a9ea8c0d5e4bdecf24
parent 59383 ca7bfd15abfd47e4d4fdb541ed1a5abe349ffb80
child 59385 b884172a3a0680629c82cdadbfcd96b732e6bd21
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
bugs607894
milestone2.0b8pre
Bug 607894 - Tab matches always appear before normal history results. r=sdwilsh a=blocking
toolkit/components/places/src/nsPlacesAutoComplete.js
--- a/toolkit/components/places/src/nsPlacesAutoComplete.js
+++ b/toolkit/components/places/src/nsPlacesAutoComplete.js
@@ -320,32 +320,26 @@ function nsPlacesAutoComplete()
     let replacementText = "AND tags IS NOT NULL";
     return this._db.createAsyncStatement(
       SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g")
     );
   });
 
   XPCOMUtils.defineLazyGetter(this, "_openPagesQuery", function() {
     return this._db.createAsyncStatement(
-      "SELECT t.url, "
-    +        "IFNULL(h.title, t.url) AS c_title, f.url, "
-    +         kBookTagSQLFragment + ", "
-    +         "h.visit_count, h.typed, "
-    +         "h.id, :query_type, t.open_count, h.frecency "
+      "SELECT t.url, t.url, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "
+    +         ":query_type, t.open_count, NULL "
     + "FROM moz_openpages_temp t "
     + "LEFT JOIN moz_places h ON h.url = t.url "
-    + "LEFT JOIN moz_favicons f ON f.id = h.favicon_id "
-    + "WHERE t.open_count > 0 "
-    +   "AND AUTOCOMPLETE_MATCH(:searchString, t.url, "
-    +                          "COALESCE(bookmark, c_title, t.url), tags, "
-    +                          "h.visit_count, h.typed, parent, "
-    +                          "t.open_count, "
+    + "WHERE h.id IS NULL "
+    +   "AND AUTOCOMPLETE_MATCH(:searchString, t.url, t.url, NULL, "
+    +                          "NULL, NULL, NULL, t.open_count, "
     +                          ":matchBehavior, :searchBehavior) "
-    + "ORDER BY h.frecency DESC, t.ROWID DESC "
-    + "LIMIT :maxResults"
+    + "ORDER BY t.ROWID DESC "
+    + "LIMIT :maxResults "
     );
   });
 
   XPCOMUtils.defineLazyGetter(this, "_typedQuery", function() {
     let replacementText = "AND h.typed = 1";
     return this._db.createAsyncStatement(
       SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g")
     );
@@ -489,17 +483,17 @@ nsPlacesAutoComplete.prototype = {
     if (this._currentSearchString)
       this._behavior = this._defaultBehavior;
     else
       this._behavior = this._emptySearchDefaultBehavior;
 
     // For any given search, we run up to four queries:
     // 1) keywords (this._keywordQuery)
     // 2) adaptive learning (this._adaptiveQuery)
-    // 3) openPages (this._openPagesQuery)
+    // 3) open pages not supported by history (this._openPagesQuery)
     // 4) query from this._getSearch
     // (1) only gets ran if we get any filtered tokens from this._getSearch,
     // since if there are no tokens, there is nothing to match, so there is no
     // reason to run the query).
     let {query, tokens} =
       this._getSearch(this._getUnfilteredSearchTokens(this._currentSearchString));
     let queries = tokens.length ?
       [this._getBoundKeywordQuery(tokens), this._getBoundAdaptiveQuery(), this._getBoundOpenPagesQuery(tokens), query] :
@@ -910,21 +904,23 @@ nsPlacesAutoComplete.prototype = {
    *         additional work.
    */
   _getBoundSearchQuery: function PAC_getBoundSearchQuery(aMatchBehavior,
                                                          aTokens)
   {
     // We use more optimized queries for restricted searches, so we will always
     // return the most restrictive one to the least restrictive one if more than
     // one token is found.
+    // Note: "openpages" behavior is supported by the default query.
+    //       _openPagesQuery instead returns only pages not supported by
+    //       history and it is always executed.
     let query = this._hasBehavior("tag") ? this._tagsQuery :
                 this._hasBehavior("bookmark") ? this._bookmarkQuery :
                 this._hasBehavior("typed") ? this._typedQuery :
                 this._hasBehavior("history") ? this._historyQuery :
-                this._hasBehavior("openpage") ? this._openPagesQuery :
                 this._defaultQuery;
 
     // Bind the needed parameters to the query so consumers can use it.
     let (params = query.params) {
       params.parent = this._bs.tagsFolder;
       params.query_type = kQueryTypeFiltered;
       params.matchBehavior = aMatchBehavior;
       params.searchBehavior = this._behavior;
@@ -942,17 +938,16 @@ nsPlacesAutoComplete.prototype = {
   },
 
   _getBoundOpenPagesQuery: function PAC_getBoundOpenPagesQuery(aTokens)
   {
     let query = this._openPagesQuery;
 
     // Bind the needed parameters to the query so consumers can use it.
     let (params = query.params) {
-      params.parent = this._bs.tagsFolder;
       params.query_type = kQueryTypeFiltered;
       params.matchBehavior = this._matchBehavior;
       params.searchBehavior = this._behavior;
       // We only want to search the tokens that we are left with - not the
       // original search string.
       params.searchString = aTokens.join(" ");
       params.maxResults = this._maxRichResults;
     }