From: pho Date: Mon, 18 Feb 2008 15:16:33 +0000 (+0900) Subject: HitPage should contain more info X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=4abf7df08bf0a614ea8179e8d1d69a17aac4f197;p=Rakka.git HitPage should contain more info darcs-hash:20080218151633-62b54-f0658121105b21dfd8d405574f36d80c5040fe1b.gz --- diff --git a/Rakka/Storage/Impl.hs b/Rakka/Storage/Impl.hs index c9c2de2..442c412 100644 --- a/Rakka/Storage/Impl.hs +++ b/Rakka/Storage/Impl.hs @@ -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 } diff --git a/Rakka/Storage/Types.hs b/Rakka/Storage/Types.hs index 28184a6..e9b848b 100644 --- a/Rakka/Storage/Types.hs +++ b/Rakka/Storage/Types.hs @@ -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) diff --git a/Rakka/Wiki/Interpreter/PageList.hs b/Rakka/Wiki/Interpreter/PageList.hs index cffd938..8631c8b 100644 --- a/Rakka/Wiki/Interpreter/PageList.hs +++ b/Rakka/Wiki/Interpreter/PageList.hs @@ -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]) ] _ -> []