@@ -1707,15 +1707,26 @@ randomTask conf connection filterExpression = do
17071707 pure $ errorsDoc & fromMaybe taskFormatted
17081708
17091709
1710+ -- | Fuzzy search for tasks matching a pattern in body, ulid, notes, or metadata
17101711findTask :: Config -> Connection -> Text -> IO (Doc AnsiStyle )
17111712findTask conf connection aPattern = do
1712- tasks :: [(Text , Text , Maybe [Text ], Maybe [Text ], Maybe Text )] <-
1713- query_
1713+ let sqlFuzzyPattern = aPattern & T. chunksOf 1 & T. intercalate (T. pack " %" )
1714+ tasksFuzzy :: [(Text , Text , Maybe [Text ], Maybe Text )] <-
1715+ query
17141716 connection
17151717 [sql |
1716- SELECT ulid, body, tags, notes, metadata
1718+ SELECT ulid, body, notes, metadata
17171719 FROM tasks_view
1720+ WHERE body LIKE '%' || ? || '%'
1721+ OR ulid LIKE '%' || ? || '%'
1722+ OR notes LIKE '%' || ? || '%'
1723+ OR metadata LIKE '%' || ? || '%'
17181724 |]
1725+ ( sqlFuzzyPattern
1726+ , aPattern -- Only match on ULID substring
1727+ , sqlFuzzyPattern
1728+ , sqlFuzzyPattern
1729+ )
17191730
17201731 let
17211732 ulidWidth = 5
@@ -1741,7 +1752,7 @@ findTask conf connection aPattern = do
17411752
17421753 -- Calculate fuzzy score for each part individually
17431754 -- and pick the highest one
1744- scoreFunc (ulid, theBody, _, mbNotes, mbMetadata) =
1755+ scoreFunc (ulid, theBody, mbNotes, mbMetadata) =
17451756 let
17461757 scoreParts =
17471758 [ ( matchFunc theBody
@@ -1776,7 +1787,7 @@ findTask conf connection aPattern = do
17761787
17771788 fstOf3 (x, _, _) = x
17781789 tasksScored =
1779- tasks
1790+ tasksFuzzy
17801791 <&> scoreFunc
17811792 & P. filter ((> minimumScore) . fstOf3)
17821793 & sortOn (Down . fstOf3)
0 commit comments