Global search for blocks with multiple keywords

Use case or problem

Currently, obsidian only allow to search for multiple terms within a note. I would like to the ability to do a global search and return the result only if those term are in the same line or under the same heading.

Implementing global search for term A and term B:

  1. Only return the search result if term A and term B are in the same line/block
    or
  • Only return the search result if term A and term B are under the same heading

Proposed solution

The search box can have options for filtering/toggle level of search.
Or create new regex operator for “pseudo blocks”

Current workaround

Using regex for return results within block/line: /.*term A.*term B.*|.*term B.*term A.*/

7 Likes

Surely you don’t need a special search syntax for search in a block? Going through the block visually is faster than typing out the search syntax, isn’t it?

I edit the request to make it more clear:

Currently, obsidian only allow to search for multiple terms within a note. I would like to the ability to do a global search and return the result only if those term are in the same line or under the same heading.

In some cases going over the results may not be efficient. I write everything on my daily note and then tag them appropriately (at the end of the line). If I search for a combination of words that span different lines then, that doesn’t serve my purpose :slight_smile:

1 Like

@1stprinciples: OK, whatever. It is a feature request, so why not.

This is a great feature request. So surprise that only few people need it.

For example, if I have 2 ideas on today’s note and one is done:

  1. balabala #idea
  2. balabalabala #idea #done
    Then I cannot use a tag search to filter the ongoing idea.

I think currently Obsidian’s ‘Block’ is only a half finished function. We only have the Block Reference. We cannot search or filter based on a block, we cannot easily create a block reference by drag-drop. Hope dev team could put more effort on it.

2 Likes

@octavius: in your example above you can search for ongoing ideas as follows:
tag:#idea -#done.

As for “Hope dev team could put more effort on it.”, it’s probably not meant as such but it sounds pretty offensive. The dev team is probably one of the hardest working, most dedicated, most accessible teams around, so please be careful in your choice of words.

1 Like

The way you search will show results of a page. (balabala and #idea not necessarily need to be on the same block/line).

The purpose of block search for me is to find the specific argument between 2 events/phenomenon (ex: causal relationship).

Understandably that this could be solve by implementing atomic note.
But @octavius point is that if this search function is implemented, then the utility of block-link function will increase (which i fully agreed).

2 Likes

@GreenChocho: @octavius has not solved it with atomic notes but by using hashtags, according to his/her example. So, he/she can filter on a particular hashtag while excluding other tags, and from there he/she can analyze trends/patterns.

Can you give an example of how you specifically would do block search?

Example: if i got articles on “Team Diversity”, which have argument on team dynamics and team cognition.

But i want to find causal arguments on the relationship between “Team Diversity” and “team cognition” only, then the current global search function will not be able to help. I need to use the workaround specified in the 1st post.

I think @octavius comment is the another way to utilize this search function. He/she want to search a specific block/line which have “balabala” and #idea together. (this could be very useful for a term which may have meaning in different #context, or being used in different #discipline)

@GreenChocho: OK, clear. But how is that unique to block searches?

Im not sure i understand you correctly, you mean ‘why global search cannot do this?’?

@GreenChocho: it is a feature request, I don’t want to make things more difficult. I was just trying understand the thinking, but it seems I am missing a point and am therefore making things difficult.

It is probably best to leave it at this. I want to thank you for your patience.

One of the example I could think of right now is if i want to collect a hypothesis statement relating to 2 constructs. Lets call them X and Y.

So my search will be: “Hypothesis” and “X” and “Y” (or regex equivalent of this search)

As all academic paper will contain “Hypothesis”, the current global results will return Note that contain X and Y

The current feature requests will give me a list of block ID for those Hypotheses.

Then I can use the “copy search results” function or the Text {expander} plugin to show all these results as embeds.

From this, i can see how many studies have explored direct effects, how many have explored conditional/mediating effect…

Or can you help clarify how I can explain clearer?

@GreenChocho

Example: if i got articles on “Team Diversity”, which have argument on team dynamics and team cognition.
But i want to find causal arguments on the relationship between “Team Diversity” and “team cognition” only, then the current global search function will not be able to help. I need to use the workaround specified in the 1st post.

How does block search make this easier than Global search?

Currently, Global search will not return the block/line results if you only search by keywords.

If you use the regex in the 1st post, then global search will return the block level results.
BUT you will have to click the “…and xx more matches” in each note to see the block.
Then you will need to manually create an embed (or use the WorkBench plugin) to send it back to your current working note.

IF this feature request is implemented. Then i can just use the copy search results function or Text Expander to gather all this block (block only, not FULL note) inside my current working note.

Possible operator:

  • scope:line
  • scope:innermost-block // useful when nested blocks are recognized
  • scope:block
  • scope:innermost-chapter
  • scope:h6-chapter
  • scope:h1-chapter
  • scope:chapter
  • scope:file // this is default now

Restricting scope at higher levels is already done by “path” and “file” operators:

  • path:“folder1/folder2” // restricts search to content of relative path like search in Windows File Explorer.
  • path:"/folder1/folder2/file3.md" // like above but restricted to one file
  • file:“file3.md”

But that is rather in another sense, matched terms still have to occur within the same file so “scope:file” is currently the upper limit for the scope.

Reference: https://publish.obsidian.md/help/Plugins/Search

Ability to nest “scope” operator in groups is desirable.
For example: “(term1 term2 scope:line) term3” to match line with term1 and term2 only in the files which contain also term3 anywhere.

scope:line would work also for table rows (like database records, although not distinguishing fields/columns)

EDIT: Partial implementation is now promissed in posts #30 and #33.


Another helpful behavior in this pursuit would be option to rank/sort search results based on closeness of keywords in the match.

2 Likes

@GreenChocho: OK, got it. The last paragraph makes the advantage of this FR clear.
Thank you, kind sir.

1 Like

I also enjoyed the discussion :smiley:

1 Like

My apologize if my tone sounds offensive. I didn’t mean it. Acturally I am so grateful that Obsidian team let me use such a great app for free. Also thanks for your advice.

tag:#idea -#done cannot filter the 1. balabala #idea, this is because the search is based on whole file not a block or a paragraph. So tag:#idea -#done give desired result.

You could try it by creating a demo.md file and copy paste these two paragraphs to the file, then search by tag:#idea -#done, you will find that the demo.md doesn’t appear on the result.

1 Like