]> gitweb @ CieloNegro.org - Rakka.git/commitdiff
HitPage should contain more info
authorpho <pho@cielonegro.org>
Mon, 18 Feb 2008 15:16:33 +0000 (00:16 +0900)
committerpho <pho@cielonegro.org>
Mon, 18 Feb 2008 15:16:33 +0000 (00:16 +0900)
darcs-hash:20080218151633-62b54-f0658121105b21dfd8d405574f36d80c5040fe1b.gz

Rakka/Storage/Impl.hs
Rakka/Storage/Types.hs
Rakka/Wiki/Interpreter/PageList.hs

index c9c2de2858320725b75c30396e54e179bcc6b3da..442c412fb4966f906598155227c115dec48e75e2 100644 (file)
@@ -16,6 +16,7 @@ import           Control.Monad
 import           Data.Maybe
 import           Data.Set (Set)
 import qualified Data.Set as S
+import           Data.Time
 import           Network.HTTP.Lucu
 import           Network.HTTP.Lucu.Utils
 import           Network.URI
@@ -25,6 +26,7 @@ import           Rakka.Page
 import           Rakka.Storage.DefaultPage
 import           Rakka.Storage.Repos
 import           Rakka.Storage.Types
+import           Rakka.W3CDateTime
 import           Subversion.Types
 import           Subversion.FileSystem
 import           Subversion.Repository
@@ -158,6 +160,7 @@ openIndex indexDir revFile
                               $ removeFile revFile
 
                      Right index <- openDatabase indexDir (Writer [Create []])
+                     addAttrIndex index "@mdate"         SeqIndex
                      addAttrIndex index "@type"          StrIndex
                      addAttrIndex index "@uri"           SeqIndex
                      addAttrIndex index "rakka:revision" SeqIndex
@@ -206,8 +209,16 @@ searchIndex index cond
       fromId :: [String] -> DocumentID -> IO HitPage
       fromId words docId
           = do uri     <- getDocURI index docId
-               rev     <- getDocAttr index docId "rakka:revision"
-                          >>= return . read . fromJust
+               rev     <- unsafeInterleaveIO $
+                          getDocAttr index docId "rakka:revision"
+                          >>=
+                          return . read . fromJust
+               lastMod <- unsafeInterleaveIO $
+                          getDocAttr index docId "@mdate"
+                          >>=
+                          return . zonedTimeToUTC . fromJust . parseW3CDateTime . fromJust
+               summary <- unsafeInterleaveIO $
+                          getDocAttr index docId "rakka:summary"
                snippet <- unsafeInterleaveIO $
                           do doc <- getDocument index docId [NoAttributes, NoKeywords]
                              sn  <- makeSnippet doc words 300 80 80
@@ -215,6 +226,8 @@ searchIndex index cond
                return HitPage {
                             hpPageName = decodePageName $ uriPath uri
                           , hpPageRev  = rev
+                          , hpLastMod  = lastMod
+                          , hpSummary  = summary
                           , hpSnippet  = snippet
                           }
 
index 28184a676e574d54989cecc80af2301dbb95a5b2..e9b848ba8cdab1527fba5db257c9ceed764288d5 100644 (file)
@@ -8,6 +8,7 @@ module Rakka.Storage.Types
     where
 
 import           Control.Concurrent.STM
+import           Data.Time
 import           Rakka.Page
 import           Subversion.Repository
 import           Subversion.Types
@@ -38,7 +39,9 @@ data SearchResult
 data HitPage
     = HitPage {
         hpPageName :: !PageName
-      , hpPageRev  :: !RevNum
+      , hpPageRev  :: RevNum
+      , hpLastMod  :: UTCTime
+      , hpSummary  :: Maybe String
       , hpSnippet  :: [SnippetFragment]
       }
     deriving (Show, Eq)
index cffd93806f20c50b490dec6af1a9ac5596198a72..8631c8b4bae98d3929b98bbe369ce69925ed429a 100644 (file)
@@ -7,7 +7,6 @@ import           Control.Monad
 import           Data.Maybe
 import           Data.Time
 import           Network.HTTP.Lucu.RFC1123DateTime
-import           Rakka.Page
 import           Rakka.Storage
 import           Rakka.Utils
 import           Rakka.Wiki
@@ -53,26 +52,20 @@ recentUpdatesInterp
                 setMax    cond items
 
                 result <- searchPages sto cond
-                pages  <- mapM (getPageByHP sto) (srPages result)
-
-                mkPageList showSummary pages
+                mkPageList showSummary (srPages result)
       }
     where
-      getPageByHP :: Storage -> HitPage -> IO Page
-      getPageByHP sto hp
-          = getPage sto (hpPageName hp) (Just (hpPageRev hp)) >>= return . fromJust
-
-      mkPageList :: Bool -> [Page] -> IO BlockElement
+      mkPageList :: Bool -> [HitPage] -> IO BlockElement
       mkPageList showSummary pages
           = do items <- mapM (mkListItem showSummary) pages
                return (Div [("class", "recentUpdates")]
                        [ Block (List Bullet items) ])
 
-      mkListItem :: Bool -> Page -> IO ListItem
+      mkListItem :: Bool -> HitPage -> IO ListItem
       mkListItem showSummary page
-          = do lastMod <- utcToLocalZonedTime (entityLastMod page)
+          = do lastMod <- utcToLocalZonedTime (hpLastMod page)
                return ( [ Inline ( PageLink {
-                                     linkPage     = Just (pageName page)
+                                     linkPage     = Just (hpPageName page)
                                    , linkFragment = Nothing
                                    , linkText     = Nothing
                                    }
@@ -82,7 +75,7 @@ recentUpdatesInterp
                                 )
                         ]
                         ++
-                        case (showSummary, entitySummary page) of
+                        case (showSummary, hpSummary page) of
                           (True, Just s)
                               -> [ Block (Paragraph [Text s]) ]
                           _   -> []