Skip to content

Commit

Permalink
Support hierarchical tags
Browse files Browse the repository at this point in the history
Works in query (#10) as `tag:foo/**/bar`
  • Loading branch information
srid committed Jun 10, 2021
1 parent 1aafda4 commit 82e8ac4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Milestone (notes.srid.ca),
- Queries
- [x] Query by tag (in code block)
- [x] Date in queries (requires Heist withJson changes)
- [ ] Hierarchical tags?
- [x] Hierarchical tags?
- [ ] Theme touches
- dd styling
- Nice to have, but not essential
Expand Down
15 changes: 6 additions & 9 deletions src/Emanote/Model/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
module Emanote.Model.Query where

import Control.Lens.Operators ((^.))
import Data.IxSet.Typed ((@=))
import Data.IxSet.Typed ((@+), (@=))
import qualified Data.IxSet.Typed as Ix
import qualified Data.Text as T
import Emanote.Model.Note (Note)
import qualified Emanote.Model.Note as N
import Emanote.Model.Type (Model, modelNotes)
import Emanote.Model.Type (Model, modelNotes, modelTags)
import Emanote.Pandoc.Markdown.Syntax.HashTag (TagPattern)
import qualified Emanote.Pandoc.Markdown.Syntax.HashTag as HT
import qualified Emanote.Route as R
Expand All @@ -27,7 +27,7 @@ instance Show.Show Query where
QueryByTag tag ->
toString $ "Pages tagged #" <> HT.unTag tag
QueryByTagPattern pat ->
toString $ "Pages tagged by " <> HT.unTagPattern pat
toString $ "Pages tagged by '" <> HT.unTagPattern pat <> "'"
QueryByPath p ->
"Pages under path '" <> p <> "'"

Expand All @@ -51,12 +51,9 @@ runQuery model = \case
QueryByTag tag ->
Ix.toList $ (model ^. modelNotes) @= tag
QueryByTagPattern pat ->
-- TODO: We don't supporting filepattern-based matching (i.e., `foo/**`) yet.
--
-- Doing it requires some consideration, such as indexing it for effecient
-- access. Or not?
let asTag = HT.Tag $ toText $ HT.unTagPattern pat
in Ix.toList $ (model ^. modelNotes) @= asTag
let allTags = fst <$> modelTags model
matchingTags = filter (HT.tagMatch pat) allTags
in Ix.toList $ (model ^. modelNotes) @+ matchingTags
QueryByPath path ->
fromMaybe mempty $ do
r <- R.mkRouteFromFilePath path
Expand Down

0 comments on commit 82e8ac4

Please sign in to comment.