lib: multiple status: query terms are OR'd (#564)

Like desc: and acct:. I think this is more intuitive and useful,
so now eg "status: status:!" works (equivalent to -UP or "not:status:*").
This commit is contained in:
Simon Michael 2017-06-10 13:31:43 -07:00
parent 7fc921db86
commit 5d28120f6d
2 changed files with 18 additions and 3 deletions

View File

@ -155,15 +155,17 @@ data QueryOpt = QueryOptInAcctOnly AccountName -- ^ show an account register fo
-- Multiple terms are combined as follows: -- Multiple terms are combined as follows:
-- 1. multiple account patterns are OR'd together -- 1. multiple account patterns are OR'd together
-- 2. multiple description patterns are OR'd together -- 2. multiple description patterns are OR'd together
-- 3. then all terms are AND'd together -- 3. multiple status patterns are OR'd together
-- 4. then all terms are AND'd together
parseQuery :: Day -> T.Text -> (Query,[QueryOpt]) parseQuery :: Day -> T.Text -> (Query,[QueryOpt])
parseQuery d s = (q, opts) parseQuery d s = (q, opts)
where where
terms = words'' prefixes s terms = words'' prefixes s
(pats, opts) = partitionEithers $ map (parseQueryTerm d) terms (pats, opts) = partitionEithers $ map (parseQueryTerm d) terms
(descpats, pats') = partition queryIsDesc pats (descpats, pats') = partition queryIsDesc pats
(acctpats, otherpats) = partition queryIsAcct pats' (acctpats, pats'') = partition queryIsAcct pats'
q = simplifyQuery $ And $ [Or acctpats, Or descpats] ++ otherpats (statuspats, otherpats) = partition queryIsStatus pats''
q = simplifyQuery $ And $ [Or acctpats, Or descpats, Or statuspats] ++ otherpats
tests_parseQuery = [ tests_parseQuery = [
"parseQuery" ~: do "parseQuery" ~: do

View File

@ -100,3 +100,16 @@ hledger -fstatus.journal print status:
>>>=0 >>>=0
# 11. multiple status: queries are OR'd
hledger -fstatus.journal print status: status:!
>>>
2017/01/01 uncleared
(a) 1
(b) 1
2017/01/02 ! pending
(a) 1
! (b) 1
>>>= 0