obsidian-tasks-group / obsidian-tasks

Task management for the Obsidian knowledge base.
https://publish.obsidian.md/tasks/
MIT License
2.41k stars 226 forks source link

Add ability to remove all or part of the global query #2074

Open david-jarman opened 1 year ago

david-jarman commented 1 year ago

⚠️ Please check that this feature request hasn't been suggested before.

🔖 Feature description

A task code block that removes the global query and/or global filter for special cases where the user wants to ignore those filters.

✔️ Solution

I have my global query set up to not search my Daily Notes directory for tasks, because I use a template that adds some daily tasks to each note that I don't always get done, and I don't go back and remove them. In my daily note template, I also have a task code block to show tasks that I have completed that day, and I want to show the tasks that I have completed from the daily note. But because my global query excludes the Daily Note directory, I have no way to query for those tasks.

In this scenario, I think it would be helpful to have a simple syntax in the tasks code block to remove the global filter and query.

```tasks remove global query remove global filter done today ```

❓ Alternatives

A more complex, but alternative approach, would be to allow tasks code blocks to negate queries in the global query. I've only considered this temporarily, I don't think it's actually a viable approach, as it would be very difficult to match query lines against each other to determine if they negate each other.

📝 Additional Context

Global query for my use case:

folder does not include 5. Templates
folder does not include Areas/Daily Notes
folder does not include 4. Archives

Task block for my daily note:

done on 2023-06-27
short mode
claremacrae commented 1 year ago

Hi thanks for using Tasks, and thanks for the suggestions.

A task code block that removes the global query

I do think that this a good idea, and will make some suggestions on the implementation in a later comment.

I will also make a separate comment about a workaround that may become possible soon-ish.

and/or global filter ...

Overriding the global filter within a session is never going to be possible, as the way the global filter works is to make tasks not even parse and store lines without the global filter. They are invisible to Tasks. So the only way to achieve removal/reversal is:

  1. Remove the global filter from the settings
  2. Restart Obsidian
claremacrae commented 1 year ago

Possible Workaround - soon-ish..

(as a general request for future bug reports, where you have provided screenshots of text, please also provide the info as text so that we can copy-and-paste, and not spend time re-typing... thank you.)

I am working towards allowing filters know the location of the query file. Once this is possible, by making your queries a bit smarter, you can have the best of both worlds...

For example, you could then do something like:

(folder does not include Areas/Daily Notes) OR ( {{query.file.folder}} includes The Folder Where I store my queries that want to include tasks in the Daily Notes folder )
david-jarman commented 1 year ago

Thanks for the info, I just threw in global filter as an afterthought, I'm really after global query removal though. And I've updated my post to have text of the queries instead of screenshots 😄

claremacrae commented 1 year ago

Implementation Notes

I was thinking the following set of instructions, or something similar, make sense, to give granular reversal:

clear filters
clear limit
clear sort by
clear group by
clear explain
clear show-hide ???

clear all

It will be important that the explain code is updated so that it shows users clearly what is going on - why some instructions in their global query (or earlier in their current query block, even) are being ignored...

Would that be acceptable?

It's less explicit than:

remove global query

... but more generally useful.

For example, it allows users to set a preferred sort order in their global query, and then override it in a few queries - whilst still retaining their filters - and so on.

david-jarman commented 1 year ago

@claremacrae, I love that idea. Being able to clear existing parts of the query would be more helpful than just removing the entire global query. I would add a clear all option as well in case a user wants to ensure their code block is truly starting from scratch.

claremacrae commented 1 year ago

@claremacrae, I love that idea. Being able to clear existing parts of the query would be more helpful than just removing the entire global query. I would add a clear all option as well in case a user wants to ensure their code block is truly starting from scratch.

Good idea. I've edited the implementation notes above to add that.

claremacrae commented 1 year ago

See also:

ilandikov commented 1 year ago

May I suggest ignore ... instead of clear ...? =) ignore global query/sort by/filters etc

how does this look for you? =)

david-jarman commented 1 year ago

To me, “ignore” implies that all filters, sort bys, etc will be ignored from now on. But what I want is to clear existing filters, then apply new ones after that. So clear still makes more sense for my use case.

claremacrae commented 1 year ago

To me, “ignore” implies that all filters, sort bys, etc will be ignored from now on. But what I want is to clear existing filters, then apply new ones after that. So clear still makes more sense for my use case.

I agree. I don't think clear is perfect, but it's the best I can think of so far, for the per-instruction-type filters like clear filters.

The one exception is ignore global query which might be a useful short-hand, as it is more specific, and would have the same meaning at any position in the tasks code block.

ilandikov commented 1 year ago

To me, “ignore” implies that all filters, sort bys, etc will be ignored from now on. But what I want is to clear existing filters, then apply new ones after that. So clear still makes more sense for my use case.

sorry I didn't get that. You wish to clear -all- the existing filters or the ones from the global query?

I think it is just easier and simpler to use ignore global query once and for all. The granularity is awesome but I doubt it will be used a lot. I would also have a use case for ignore global query.

I agree. I don't think clear is perfect, but it's the best I can think of so far, for the per-instruction-type filters like clear filters.

Does this imply we will need to take care of the order the lines in the query are constructed?

claremacrae commented 1 year ago

To me, “ignore” implies that all filters, sort bys, etc will be ignored from now on. But what I want is to clear existing filters, then apply new ones after that. So clear still makes more sense for my use case.

sorry I didn't get that. You wish to clear -all- the existing filters or the ones from the global query?

Yes, it means to clear all filters read before the clear line.

So to clarify a bit more...

When a tasks query block is run, the following happens, effectively:

paste in all the text in the global query settings
paste in all the text in the tasks query block

At the point of executing the search, this is seen as a single query block...

I personally feel that a clear filters instruction is beneficial as it can be used in any location.

I think it is just easier and simpler to use ignore global query once and for all. The granularity is awesome but I doubt it will be used a lot. I would also have a use case for ignore global query.

Re "I doubt it will be used a lot", I am super happy providing features that are useful for the general case (overriding the global query) but also have value in other situations too.

I agree. I don't think clear is perfect, but it's the best I can think of so far, for the per-instruction-type filters like clear filters.

Does this imply we will need to take care of the order the lines in the query are constructed?

Absolutely... But as that happens anyway, it's not a problem.

The hardest thing about this request is going to be quite a lot of extra work that is needed for the feature to be clear to users of explain.

ilandikov commented 1 year ago
  • It could be put near the start of the tasks query block, in which case it effectively deletes an filters read from the global query settings

I guess you mean filters, sort bys, etc

  • It can be used part-way through the tasks query block, in which case it also delete any filters earlier on in the query.

I really like this approach, thanks a lot for your detailed clarification =)

david-jarman commented 10 months ago

Looks completed,thanks so much for shipping this so quickly!

claremacrae commented 10 months ago

Thanks, but reopening as only the ability to clear all of the global query was implemented initially, not selective clearing.

claremacrae commented 9 months ago

Just noting progress so far:

I am looking at the other requests here, to see if I can do anything relatively easily.