Let `tag:` and `section: work together in search

Use case or problem

Basically, I’d like to use tag: for section: .

For example, I have the following .md files:

test_search/test1.md

## test1-heading1 #tag2 #tag3

test1-111111

## test1-heading2

test1-222222

```
#tag2 #tag3
```

test_search/test2.md

## test2-heading1 #tag2

test2-111111

## test2-heading2 #tag2 

test2-222222

## test2-heading3 #tag3

test2-333333

test_search/test3.md

## test3 #tag3

test3-333333

My purpose is to search all the sections that contain both two tags, i.e. #tag2 and #tag3.

A naive approach is to use section:(#tag2 #tag3), the result is:

Note that

  1. It included two results instead of one. The 2nd is in the code block and they are not tags!

  2. I have turn on the “Explain search term”, it shown that engine was matching text rather than tag.

The obsidian doc says that

Note: Since tag: ignores matches in code blocks and in non-Markdown content, it’s often faster and more accurate than a normal full-text search for #work.

Thus I tried to nest tag: inside section::

section:((tag: tag2) (tag: tag3))

However it doesn’t work.

The “Explain search term” says

Operator “tag” cannot be nested within “section”.

Ideally, searching should be able to make tag: and section: work together, e.g. supports tag: to be nested within section:.

Thanks.

Proposed solution

Enhance the query language.

Current workaround (optional)

Use the naive approach, i.e. section:(#tag2 #tag3).

Related feature requests (optional)

1 Like

+1 :pray: