1
1
mirror of https://github.com/aelve/guide.git synced 2024-11-23 04:07:14 +03:00

Fix 'extractKeyword' to not concatenate keywords

Before:

    > extractKeyword "https://google.com?q=foo&p=bar"
    Just "foobar"

After:

    > extractKeyword "https://google.com?q=foo&p=bar"
    Just "foo"
This commit is contained in:
Artyom 2017-07-10 00:52:46 +03:00
parent 0c5e8c874b
commit ba8b772b22
No known key found for this signature in database
GPG Key ID: B8E35A33FF522710

View File

@ -272,13 +272,19 @@ extractQuery url = getQuery <$> parse url
getQuery = parseQuery . T.toByteString . URI.uriQuery
parse = URI.parseURI . T.toString
-- TODO: different search engines have different parameters, we should use
-- right ones instead of just trying “whatever fits”
extractKeyword :: Url -> Maybe Text
extractKeyword url
= case extractQuery url of
Just query -> T.toStrict <$> lookupQuery query
Nothing -> Nothing
where
lookupQuery = join . (lookup "q" <> lookup "p" <> lookup "text")
lookupQuery :: [(ByteString, Maybe ByteString)] -> Maybe ByteString
lookupQuery query = join $
lookup "q" query <|> -- Google, Bing, Ecosia, DDG
lookup "p" query <|> -- Yahoo
lookup "text" query -- Yandex
toReferrerView :: Url -> ReferrerView
toReferrerView url