<commit_before>module Handler.Blog where

import Import
import Yesod.Paginator
import Helper.MakeBrief
import Data.Time.Format.Human
import Data.Time
import qualified Data.Text as T (concat)
import Database.Persist.GenericSql

getBlogViewR :: Handler RepHtml
getBlogViewR = do
  -- Get the list of articles inside the database
  let page = 10
  now <- liftIO $ getCurrentTime
  (articles, widget) <- runDB $ selectPaginated page [] [Desc ArticleCreatedAt]
  articleArchives <- runDB $ selectList [] [Desc ArticleCreatedAt, LimitTo 10]
  -- We'll need the two "objects": articleWidget and enctype
  -- to construct the form (see templates/articles.hamlet).
  defaultLayout $ do
    setTitle "Internal Blog"
    $(widgetFile "view")

getSearchR :: Text -> Handler RepHtml
getSearchR searchString = do
    articles <- selectArticles searchString
    now <- liftIO $ getCurrentTime
    defaultLayout $ do
      $(widgetFile "search")
  where
    selectArticles :: Text -> Handler [Entity Article]
    selectArticles t = runDB $ rawSql s [toPersistValue $ T.concat ["%", t, "%"]]
      where s = "SELECT ?? FROM article WHERE content LIKE ?"<commit_msg>add Order by to raw sql<commit_after>module Handler.Blog where

import Import
import Yesod.Paginator
import Helper.MakeBrief
import Data.Time.Format.Human
import Data.Time
import qualified Data.Text as T (concat)
import Database.Persist.GenericSql

getBlogViewR :: Handler RepHtml
getBlogViewR = do
  -- Get the list of articles inside the database
  let page = 10
  now <- liftIO $ getCurrentTime
  (articles, widget) <- runDB $ selectPaginated page [] [Desc ArticleCreatedAt]
  articleArchives <- runDB $ selectList [] [Desc ArticleCreatedAt, LimitTo 10]
  -- We'll need the two "objects": articleWidget and enctype
  -- to construct the form (see templates/articles.hamlet).
  defaultLayout $ do
    setTitle "Internal Blog"
    $(widgetFile "view")

getSearchR :: Text -> Handler RepHtml
getSearchR searchString = do
    articles <- selectArticles searchString
    now <- liftIO $ getCurrentTime
    defaultLayout $ do
      $(widgetFile "search")
  where
    selectArticles :: Text -> Handler [Entity Article]
    selectArticles t = runDB $ rawSql s [toPersistValue $ T.concat ["%", t, "%"]]
      where s = "SELECT ?? FROM article WHERE content LIKE ? ORDER BY created_at DESC"
{'fraction_non_alphanumeric': 0.09180609180609181, 'fraction_numerical': 0.003432003432003432, 'mean_word_length': 3.899159663865546, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1494721', 'n_tokens_mistral': 702, 'n_tokens_neox': 657, 'n_words': 237}