]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Storage/Impl.hs
improvements related to page search
[Rakka.git] / Rakka / Storage / Impl.hs
index 200423ffc644f94c02860bab754323b7896f64f4..c9c2de2858320725b75c30396e54e179bcc6b3da 100644 (file)
@@ -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