X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Rakka.git;a=blobdiff_plain;f=Rakka%2FStorage%2FImpl.hs;h=c9c2de2858320725b75c30396e54e179bcc6b3da;hp=200423ffc644f94c02860bab754323b7896f64f4;hb=b4c0033f297c28d95ad9298b489126331224bc42;hpb=529f792d338c75910079903e143d4dd21bd806c3 diff --git a/Rakka/Storage/Impl.hs b/Rakka/Storage/Impl.hs index 200423f..c9c2de2 100644 --- a/Rakka/Storage/Impl.hs +++ b/Rakka/Storage/Impl.hs @@ -186,12 +186,24 @@ syncIndex' index revFile repos mkDraft mapM_ (updateIndex index repos mkDraft newRev) (S.toList pages) -searchIndex :: Database -> Condition -> IO [SearchResult] +searchIndex :: Database -> Condition -> IO SearchResult searchIndex index cond = do (ids, hint) <- searchDatabase' index cond - mapM (fromId $ map fst hint) ids + let (total, words) = parseHint hint + pages <- mapM (fromId words) ids + return SearchResult { + srTotal = total + , srPages = pages + } where - fromId :: [String] -> DocumentID -> IO SearchResult + parseHint :: [(String, Int)] -> (Int, [String]) + parseHint xs + = let total = fromJust $ lookup "" xs + words = filter (/= "") $ map fst xs + in + (total, words) + + fromId :: [String] -> DocumentID -> IO HitPage fromId words docId = do uri <- getDocURI index docId rev <- getDocAttr index docId "rakka:revision" @@ -200,10 +212,10 @@ searchIndex index cond do doc <- getDocument index docId [NoAttributes, NoKeywords] sn <- makeSnippet doc words 300 80 80 return (trim (== Boundary) $ map toFragment sn) - return SearchResult { - srPageName = decodePageName $ uriPath uri - , srPageRev = rev - , srSnippet = snippet + return HitPage { + hpPageName = decodePageName $ uriPath uri + , hpPageRev = rev + , hpSnippet = snippet } toFragment :: Either String (String, String) -> SnippetFragment