diff --git a/CHANGES.txt b/CHANGES.txt
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,8 @@
 Changelog for Hoogle
 
+5.0.10
+    #205, change how the link URL is computed
+    #206, put newer versions of a package first
 5.0.9
     #202, add --haddock functionality
 5.0.8
diff --git a/hoogle.cabal b/hoogle.cabal
--- a/hoogle.cabal
+++ b/hoogle.cabal
@@ -1,7 +1,7 @@
 cabal-version:      >= 1.18
 build-type:         Simple
 name:               hoogle
-version:            5.0.9
+version:            5.0.10
 license:            BSD3
 license-file:       LICENSE
 category:           Development
@@ -15,7 +15,7 @@
     or by approximate type signature.
 homepage:           http://hoogle.haskell.org/
 bug-reports:        https://github.com/ndmitchell/hoogle/issues
-tested-with:        GHC==8.0.1, GHC==7.10.3, GHC==7.8.4, GHC==7.6.3
+tested-with:        GHC==8.0.2, GHC==7.10.3, GHC==7.8.4, GHC==7.6.3
 extra-doc-files:
     README.md
     CHANGES.txt
diff --git a/html/hoogle.js b/html/hoogle.js
--- a/html/hoogle.js
+++ b/html/hoogle.js
@@ -251,7 +251,7 @@
 function searchPlugin()
 {
     var url = $("link[rel=search]").attr("href");
-    if (url.substring(0, prefixUrl.length) != prefixUrl)
+    if (url.indexOf('://') === -1 || url.indexOf('//') !== 0 )
         url = prefixUrl + url;
     window.external.AddSearchProvider(url);
 }
diff --git a/html/index.html b/html/index.html
--- a/html/index.html
+++ b/html/index.html
@@ -34,6 +34,6 @@
 #{body}
             <div class="push"></div>
         </div>
-        <div id="footer">&copy; <a href="http://ndmitchell.com">Neil Mitchell</a> 2004-2016, version #{version}</div>
+        <div id="footer">&copy; <a href="http://ndmitchell.com">Neil Mitchell</a> 2004-2017, version #{version}</div>
     </body>
 </html>
diff --git a/src/Action/Generate.hs b/src/Action/Generate.hs
--- a/src/Action/Generate.hs
+++ b/src/Action/Generate.hs
@@ -15,6 +15,7 @@
 import qualified Data.Text as T
 import Control.Monad.Extra
 import Data.Monoid
+import Data.Ord
 import System.Console.CmdArgs.Verbosity
 import Prelude
 
@@ -128,7 +129,12 @@
 readHaskellDirs :: Timing -> Settings -> [FilePath] -> IO (Map.Map String Package, Set.Set String, Source IO (String, URL, LStr))
 readHaskellDirs timing settings dirs = do
     files <- concatMapM listFilesRecursive dirs
-    let packages = map (takeBaseName &&& id) $ filter ((==) ".txt" . takeExtension) files
+    -- We reverse/sort the list because of #206
+    -- Two identical package names with different versions might be foo-2.0 and foo-1.0
+    -- We never distinguish on versions, so they are considered equal when reodering
+    -- So put 2.0 first in the list and rely on stable sorting. A bit of a hack.
+    let order a = second Down $ parseTrailingVersion a
+    let packages = map (takeBaseName &&& id) $ sortOn (map order . splitDirectories) $ filter ((==) ".txt" . takeExtension) files
     cabals <- mapM parseCabal $ filter ((==) ".cabal" . takeExtension) files
     let source = forM_ packages $ \(name, file) -> do
             src <- liftIO $ strReadFile file
diff --git a/src/General/Util.hs b/src/General/Util.hs
--- a/src/General/Util.hs
+++ b/src/General/Util.hs
@@ -16,6 +16,7 @@
     Average, toAverage, fromAverage,
     inRanges,
     readMaybe,
+    parseTrailingVersion,
     exitFail,
     prettyTable,
     ghcApiVersion,
@@ -321,6 +322,16 @@
         isLegal c = isAscii c && isAlphaNum c
 
 
+parseTrailingVersion :: String -> (String, [Int])
+parseTrailingVersion = (reverse *** reverse) . f . reverse
+    where
+        f xs | (ver@(_:_),sep:xs) <- span isDigit xs
+             , sep == '-' || sep == '.'
+             , (a, b) <- f xs
+             = (a, Prelude.read (reverse ver) : b)
+        f xs = (xs, [])
+
+
 -- | Equivalent to any (`inRange` x) xs, but more efficient
 inRanges :: Ix a => [(a,a)] -> (a -> Bool)
 inRanges xs = \x -> maybe False (`inRange` x) $ Map.lookupLE x mp
@@ -344,3 +355,8 @@
         splitPair "-" "module-" === ("module","")
     testing_ "General.Util.inRanges" $ do
         quickCheck $ \(x :: Int8) xs -> inRanges xs x == any (`inRange` x) xs
+    testing "General.Util.parseTrailingVersion" $ do
+        let a === b = if a == b then putChar '.' else error $ show (a,b)
+        parseTrailingVersion "shake-0.15.2" === ("shake",[0,15,2])
+        parseTrailingVersion "test-of-stuff1" === ("test-of-stuff1",[])
+
diff --git a/src/Output/Tags.hs b/src/Output/Tags.hs
--- a/src/Output/Tags.hs
+++ b/src/Output/Tags.hs
@@ -53,7 +53,7 @@
 
     storeWrite store Completions $ join0 $
         takeWhile ("set:" `isPrefixOf`) (map fst categories) ++
-        map ("package:"++) (sortOn lower $ filter keep $ map fst packages) ++
+        map ("package:"++) (sortOn lower $ nubOrd $ filter keep $ map fst packages) ++
         map (joinPair ":") (sortOn (weightTag &&& both lower) $ nubOrd [ex | (p,_) <- packages, keep p, ex <- extra p, fst ex /= "set"])
     where
         addRange :: [(String, [(Maybe TargetId,a)])] -> [(String, (TargetId, TargetId))]
