76
Knowhow Trading Post / Victory Over The Sucky Firefox 3 Address Bar!
« on: July 03, 2008, 09:21:37 am »
Also known as the "AwesomeBar", but more like dead PossumBar! amirite? :-) Firefox 3 includes a completely reworked autocomplete/search system for the URL/address bar. The upside is you get pretty results with a bit more info in the pop up, and it makes for a great way to search through recent history or pages where you know the title but not the URL. The downside is that it's about as dumb as a brick when it comes to prioritizing things.
It's got a complex algorithm that ranks URLs based on how frequently you vist them, if they're book marked, how long since your last vist, if you went via a link or typed it directly, etc. As you type, it searches both the URL, page title, and any tags/comments you've assigned your bookmarks. The problem comes in that it searchs ANYWHERE in those, including in the middle of words.
A quick example:
If you frequently vist a site called, say ozyandmille.org, then that site gets a high priority. You might also frequent a site called commissionedcomic.com, and maybe missmab.com as well. Now, you want to go visit that last site, and you don't load it quite as often as the other two, but you still know it by name. So you start typing something logical, like say, the url. You get the "mi" done, and you'd expect it to be listing "missmab.com" as the autocompletion option. But no, it's not. comMIssionedcoMIc.com comes first, as it matches that "mi" four times, two in the url, and two more in the page title. Next is ozyandMIillie, for the same reasons, then finally "MIssmab.com" since it's only got one hit. Now, if you go back a lot of times, and keeping typing the same "mi" letters then picking the correct address, it will eventually learn to asscociate "mi" with missmab.com Yet if you then go and type "mis" later, you're gonna see "comMISionedcomic.com" at the top again, until you train that new, three letter sequence. For a place where you're supposed to type urls, that seems pretty stupid to me.
Don't get me wrong, I still want it to do fancy searching when I type in crazy stuff, but I want it to prioritze results where the URL starts with exactly what I started typing. At first, I thought I could do it via a firefox add-on... there's several out there of the "old location bar" type. Problem is, they all just use a couple visual tricks to make it look like the old firefox 2 behavior, without really fixing the underlying search algorithm. So I started hunting through code myself. It took me about 10 hours, as I had NO idea how firefox even works at that level, and I've never coded in any of the languages it uses. But I finally narrowed down it's search to a very small section of code that's actually using an SQL query to rank things. Now SQL, THAT I understand!
So the result is I've made a small patch that applies against the FF3 code, changing that query so that it gives 500 bonus points in the ranking to places where the start of the URL (minus the http://, www.) matches what you've typed. So far, it's working how I expected, but anyone else out there who feels daring, I could use more testers. This means you have to be comfortable compiling firefox from source code, which probably means very few of you. Hopefully I can still figure out a way to get it into add-on format, which can then be easily installed by anyone. For now though, here's the patch.
Oh, quick note... this bit of code is hiding inside XULRunner... so if you normally building firefox against XUL runner, (rather than directly) you'll actually need to patch/rebuild XULRunner instead.
EDIT: Updated the patch to use "REPLACE" instead of "TRIM" as it was breaking sites that started with h, t, p, or w (aka, the http and www trims.)
EDIT2: No luck making an add-on. This code is deep in the basic functionality of the browser. The only way to do it as an add-on would be to completely implement a completely seperate/new address bar widget from scratch to completely replace the existing one. Darn!
It's got a complex algorithm that ranks URLs based on how frequently you vist them, if they're book marked, how long since your last vist, if you went via a link or typed it directly, etc. As you type, it searches both the URL, page title, and any tags/comments you've assigned your bookmarks. The problem comes in that it searchs ANYWHERE in those, including in the middle of words.
A quick example:
If you frequently vist a site called, say ozyandmille.org, then that site gets a high priority. You might also frequent a site called commissionedcomic.com, and maybe missmab.com as well. Now, you want to go visit that last site, and you don't load it quite as often as the other two, but you still know it by name. So you start typing something logical, like say, the url. You get the "mi" done, and you'd expect it to be listing "missmab.com" as the autocompletion option. But no, it's not. comMIssionedcoMIc.com comes first, as it matches that "mi" four times, two in the url, and two more in the page title. Next is ozyandMIillie, for the same reasons, then finally "MIssmab.com" since it's only got one hit. Now, if you go back a lot of times, and keeping typing the same "mi" letters then picking the correct address, it will eventually learn to asscociate "mi" with missmab.com Yet if you then go and type "mis" later, you're gonna see "comMISionedcomic.com" at the top again, until you train that new, three letter sequence. For a place where you're supposed to type urls, that seems pretty stupid to me.
Don't get me wrong, I still want it to do fancy searching when I type in crazy stuff, but I want it to prioritze results where the URL starts with exactly what I started typing. At first, I thought I could do it via a firefox add-on... there's several out there of the "old location bar" type. Problem is, they all just use a couple visual tricks to make it look like the old firefox 2 behavior, without really fixing the underlying search algorithm. So I started hunting through code myself. It took me about 10 hours, as I had NO idea how firefox even works at that level, and I've never coded in any of the languages it uses. But I finally narrowed down it's search to a very small section of code that's actually using an SQL query to rank things. Now SQL, THAT I understand!
So the result is I've made a small patch that applies against the FF3 code, changing that query so that it gives 500 bonus points in the ranking to places where the start of the URL (minus the http://, www.) matches what you've typed. So far, it's working how I expected, but anyone else out there who feels daring, I could use more testers. This means you have to be comfortable compiling firefox from source code, which probably means very few of you. Hopefully I can still figure out a way to get it into add-on format, which can then be easily installed by anyone. For now though, here's the patch.
Code: [Select]
--- a/toolkit/components/places/src/nsNavHistoryAutoComplete.cpp 2008-05-26 21:28:47.000000000 -0500
+++ b/toolkit/components/places/src/nsNavHistoryAutoComplete.cpp 2008-07-03 03:07:40.054630131 -0500
@@ -276,12 +276,13 @@
sql = NS_LITERAL_CSTRING(
"SELECT h.url, h.title, f.url") + BOOK_TAG_SQL + NS_LITERAL_CSTRING(", "
- "ROUND(MAX(((i.input = ?2) + (SUBSTR(i.input, 1, LENGTH(?2)) = ?2)) * "
- "i.use_count), 1) rank "
- "FROM moz_inputhistory i "
- "JOIN moz_places h ON h.id = i.place_id "
+ "((SUBSTR(REPLACE(REPLACE(h.url, 'http://', ''), 'www.', ''), 1, LENGTH(?2)) = ?2) * 500) + "
+ "ifnull(ROUND(MAX(((i.input = ?2) + (SUBSTR(i.input, 1, LENGTH(?2)) = ?2)) "
+ " * i.use_count), 1),0) rank "
+ "FROM moz_places h "
+ "LEFT JOIN moz_inputhistory i ON i.place_id = h.id "
"LEFT OUTER JOIN moz_favicons f ON f.id = h.favicon_id "
- "GROUP BY i.place_id HAVING rank > 0 "
+ "GROUP BY h.id HAVING rank > 0 "
"ORDER BY rank DESC, h.frecency DESC");
rv = mDBConn->CreateStatement(sql, getter_AddRefs(mDBAdaptiveQuery));
NS_ENSURE_SUCCESS(rv, rv);
Oh, quick note... this bit of code is hiding inside XULRunner... so if you normally building firefox against XUL runner, (rather than directly) you'll actually need to patch/rebuild XULRunner instead.
EDIT: Updated the patch to use "REPLACE" instead of "TRIM" as it was breaking sites that started with h, t, p, or w (aka, the http and www trims.)
EDIT2: No luck making an add-on. This code is deep in the basic functionality of the browser. The only way to do it as an add-on would be to completely implement a completely seperate/new address bar widget from scratch to completely replace the existing one. Darn!