-createSearchList = (value) ->
-        searchValue = value.replace(/^\s+/, '')
-        searchValue = searchValue.replace(/\s+$/, '')
-        keywords = searchValue.split " "
+Identifier =
+        ALBUM: "a"
+        TITLE: "t"
+        ARTIST: "r"
+
+normalizeKey = (value) ->
+        normalized = value
+        normalized = normalized.replace(/\s+/, '-')
+        normalized = normalized.replace(/-+/, '-')
+        normalized = normalized.replace(/^-+/, '')
+        normalized = normalized.replace(/-+$/, '')
+
+        normalized = normalized.toLowerCase()
+
+        normalized = normalized.replace("album:", "#{Identifier.ALBUM}:")
+        normalized = normalized.replace("title:", "#{Identifier.TITLE}:")
+        normalized = normalized.replace("artist:", "#{Identifier.ARTIST}:")
+
+        return normalized
+
+
+parseKeywords = (searchValue) ->
+        cleaned = searchValue.replace(/^\s+/, '')
+        cleaned = cleaned.replace(/\s+$/, '')
+        keywords = cleaned.split /\s+/
         keywordsNormalized = []
         for keyword in keywords
                 if keyword == ""
                         continue
-                keywordsNormalized.push keyword.toLowerCase()
-        keywordsNormalized.sort (a, b) ->
+                keywordsNormalized.push normalizeKey keyword
+        return keywordsNormalized
+
+
+createSearchList = (keywords) ->
+        unorderedKeywords = [keyword for keyword in keywords]
+        unorderedKeywords.sort (a, b) ->
                 if (b.length - a.length) == 0
                         if a == b
                                 return 0

                        @searchDatabase.push createSearchIndex song
                        # @searchDatabase.push song.filename

        search: (value) =>
                keywords = createSearchList value
                cacheKey = keywords.join " "
                if cacheKey of @searchCache
                        return @searchCache[cacheKey]

                baseCacheKey = cacheKey
                searchIndexes = @searchCache[""]
                while baseCacheKey != ""
                        if baseCacheKey of @searchCache
                                searchIndexes = @searchCache[baseCacheKey]
                                break
                        baseCacheKey =  baseCacheKey.substring 0, baseCacheKey.length - 1
                result = []
                for index in searchIndexes
                        haystack = @searchDatabase[index]
                        found = true
                        for keyword in keywords
                                if haystack.indexOf(keyword) == -1
                                        found = false
                                        break
                        if found == true
                                result.push index
                @searchCache[cacheKey] = result
                return result



                return b.length - a.length
        lastKeyword = null
        keywordsUnique = []
        for keyword in unorderedKeywords
                if keyword != lastKeyword
                        keywordsUnique.push keyword
                lastKeyword = keyword
