Search in files with multiple Tags

I often need to search within a number of files which have multiple tags. E.g a file tagged with “Active” and “2019” and “Supplier”

With the “Tag View” in DV 2 it was easy to Ctrl Click multiple tags, and then in the resultant file list, use “Search in Selection” and easily find what I need.

I know “Tag View” is not in DV 3, but assume there is still a method of achieving the same end result?

You could simply click on multiple tags in the Tag ‘cloud’, and have them all added chronologically, to narrow down the search?

But I think I might be misunderstanding what you asked? The “tag view” – what do you mean by that?

Just playing around with this instead of working, but…

How about this to search for documents with three tags (tag1, tag2, tag3):

a) In the side bar, in Global Tags, click on the database name. This will show you all that database’s tags in the list view.

b) Edit > Find in Database (cmd-alt-f) and you’ll open the main database search screen.

c) Type tags: tag1, tag2, tag3 - ie with a comma between the tags.

With very quick testing, that seems to work. It’s not the same as DT2, but it has got some advantages, because you can use wildcards. You can save common search configurations as well.

In DV 2 there is a standard “View” called “As Tags”.

That switches the view where all the tags are listed alphabetically down the right hand side pane. Ctrl Click any selection of these will provide a quick search result - which can be further searched with “in selection”.

For me it is extremely quick, and very useful.

I can do the same creating a smart group each time, but that is much more work.

@Brookter - I tried your suggestion, but it does not work with my data. When I add a comma after the first tag, the number of results immediately shrinks, (no idea why), and shrinks again when adding another tag.

I also tried using AND and OR between the tags, but that does not work.

Isn’t that what you want? To find the documents with all three tags? If you want to all the documents with any of them, then try entering this in the search field.

any: tags:test1,test2,test3

This gives me:

I didn’t know the exact syntax, and instead used the Advanced Search (with the three drop down boxes which are the same you get in Smart Groups). Once you’ve done that, DT3 adds the correct syntax to the search field, so you can learn it…

BTW, I’m not defending the decision to remove the Tag View, just experimenting with a way round it for the time being. HTH.

As @Cassady has suggested, (1) click on the group you want to analysis on the sidebar, (2) click on this icon image at the bottom of the sidebar.
Once you do that, you can choose multiple tags either by drilling down in the tag cloud, or by entering the tags in the tag filter that is located at the top of the view pane:

1 Like

I’d not come across that – thanks!

But after after playing it for a few minutes, I’m not sure how you get it to show documents with tag1 OR tag2 OR tag3, rather than AND? (You can select more than one in the tag cloud with cmd-click, but it doesn’t seem to move them into the filter bar.)

The Tag Cloud is exclusionary, ie. it filters out unrelated Tags when one is selected. This means it doesn’t support an OR function.

You can do an OR search like so, noting Any is equal to OR…

Item is Tagged just ensures only tagged files are returned. Since I’m looking for a required tag in the next criterion, it’s redundant but also not harmful (and to show another available criterion).

Also, if I removed the required Tag from this search, the Tag is not freeware would match untagged files as well. Likely not the results desired.

1 Like

I would also love to have an OR functionality in the tag cloud. Building a new search such as the one you describe is cumbersome and time consuming. Since you can cmd-click multiple tags in the tag cloud, would it be possible to write an apple script that would build the search you described above, combining the tags that are already in the tag filter (in an AND search) with the tags that were selected using cmd-click (in an OR search)? I don’t know the applescript functions for working with the tags in the tag filter or to access the currently selected tags in the tag cloud.

I have the same question, an Applescript to search for document with “tags:#Actionable-Goal tags!=-Archive”
This works well within Devonthink, but fails in Applescript
I’m currently using Smart Groups as a work-around

This script creates an “OR” query for selected tags of window 1, then opens a new window and sets its query. It’s not what you are discussing here but might get you started.

-- Open new window with query set to selected tags of window 1
-- Note: Select tags in the item list, not in the navigation sidebar

tell application id "DNtp"
	try
		set theTags to name of selected records
		if theTags = {} then error "Please select some tags"
		set theQuery to "any: tags:" & my tid(theTags, ";")
		set newWindow to open window for record root of current database
		set search query of newWindow to theQuery
		activate
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

on tid(theList, theDelimiter)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	set theString to theList as text
	set AppleScript's text item delimiters to d
	return theString
end tid

Do you mean… set theTags to tags of selected records ?

No, I named it that way because user has to select tags in the item list. theTagRecords would have been a better name …

Ahh… I see what you’re doing now.

So, we’re back to search within Devonthink
I guess my next Applescript step is to retrieve the records listed in newWindow

1 Like

I thought you were talking about UI searches. You can get the search results via search results of think window 1, however if you only want to use results in a script then there’s no need to open a new window:

-- Search with query built from selected tags of window 1
-- Note: Select tags in the item list, not in the navigation sidebar

tell application id "DNtp"
	try
		set theTags to name of selected records
		if theTags = {} then error "Please select some tags"
		set theQuery to "any: tags:" & my tid(theTags, ";")
		set theResults to search theQuery in root of current database
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

on tid(theList, theDelimiter)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	set theString to theList as text
	set AppleScript's text item delimiters to d
	return theString
end tid

A search query just automates a toolbar search.
If you’re looking to just get search results, use search.

Which fails in Applescript (tags:#Actionable-Goal tags!=-Archive)

You’re trying to do an OR search for tags:#Actionable-Goal tags!=-Archive ?

I guess I should have specified AND but it still doesn’t work

As I said, I switched to using the Smart Groups feature
Acess in Applescript is via the link URL, and then I retrieve the listed records