Commit 9d4d3c13 authored by Michael Hanus 's avatar Michael Hanus

search made case-independent

parent b864e1da
......@@ -19,6 +19,7 @@ module CPM.Repository
, updateRepository
) where
import Char (toLower)
import Directory
import Either
import List
......@@ -51,18 +52,22 @@ findAllVersions (Repository ps) p pre = sortedByVersion $ preFiltered $ sameName
filterPre p' = pre || (not . isPreRelease . version) p'
--- Search the names and synopses of all packages in the repository for a
--- particular term. Returns the newest matching version of each package.
--- particular term. Lower/upercase is ignored for the search.
--- Returns the newest matching version of each package.
--- @param repo - the repository
--- @param q - the term to search for
searchPackages :: Repository -> String -> [Package]
searchPackages (Repository ps) q = map (head . sortedByVersion) groupedResults
searchPackages (Repository ps) searchstring =
map (head . sortedByVersion) groupedResults
groupedResults = groupBy namesEqual allResults
allResults = filter matches ps
matches p = q `isInfixOf` (name p) || q `isInfixOf` (synopsis p)
allResults = filter (matches (lowerS searchstring)) ps
matches q p = q `isInfixOf` (lowerS $ name p) ||
q `isInfixOf` (lowerS $ synopsis p)
namesEqual a b = (name a) == (name b)
sortedByVersion = sortBy (\a b -> (version a) `vgt` (version b))
lowerS = map toLower
--- Get all packages in the repository and group them by versions
--- (newest first).
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment