Skip to content

adding exact phrase checkbox to search form #433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Network/Gitit/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ goToPage = withData $ \(params :: Params) -> do

searchResults :: Handler
searchResults = withData $ \(params :: Params) -> do
let patterns = pPatterns params `orIfNull` [pGotoPage params]
let patterns = if pExactPhrase params
then [unwords (pPatterns params)]
else pPatterns params `orIfNull` [pGotoPage params]
fs <- getFileStore
matchLines <- if null patterns
then return []
Expand Down
3 changes: 3 additions & 0 deletions Network/Gitit/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ data Params = Params { pUsername :: String
, pSince :: Maybe UTCTime
, pRaw :: String
, pLimit :: Int
, pExactPhrase :: Bool
, pPatterns :: [String]
, pGotoPage :: String
, pFileToDelete :: String
Expand Down Expand Up @@ -318,6 +319,7 @@ instance FromData Params where
ds <- look' "destination" `mplus` return ""
ra <- look' "raw" `mplus` return ""
lt <- lookRead "limit" `mplus` return 100
ph <- (look' "exactphrase" >> return True) `mplus` return False
pa <- look' "patterns" `mplus` return ""
gt <- look' "gotopage" `mplus` return ""
ft <- look' "filetodelete" `mplus` return ""
Expand Down Expand Up @@ -357,6 +359,7 @@ instance FromData Params where
, pDestination = ds
, pRaw = ra
, pLimit = lt
, pExactPhrase = ph
, pPatterns = words pa
, pGotoPage = gt
, pFileToDelete = ft
Expand Down
9 changes: 5 additions & 4 deletions data/templates/sitenav.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
$endif$
<li><a href="$base$/Help">Help</a></li>
</ul>
<form action="$base$/_search" method="get" id="searchform">
<input type="text" name="patterns" id="patterns"/>
<input type="submit" name="search" id="search" value="Search"/>
</form>
<form action="$base$/_go" method="post" id="goform">
<input type="text" name="gotopage" id="gotopage"/>
<input type="submit" name="go" id="go" value="Go"/>
</form>
<form action="$base$/_search" method="get" id="searchform">
<input type="text" name="patterns" id="patterns"/>
<input type="submit" name="search" id="search" value="Search"/><br\>
<input type="checkbox" name="exactphrase" id="exactphrase">&nbsp;Exact Phrase
</form>
</fieldset>
</div>