Search in a database but exclude groups

Hi,

is there a way to search in a database but exclude groups and its children?

Thanks

What exactly do you want – exclude (title) or include groups (text)?

Include a title and exclude a group
Sorry, just realised i used the wrong word in my post

Example:
Content contains „insurance“ and not in group „insurance documents“

If you always want to exclude certain groups in your search, perhaps the easiest way is just to enable the exclude from search in the generic inspector (^1) for the groups and their items.

Thanks but this would just be for one-off queries

I don’t think that’s possible, unless you use the approach suggested by ngan

I don’t use this method, but a quick test shows that I only need to exclude the main group, not the items under it - so it’s rather straight forward. Perhaps the best way is to try it first by yourself and see if it works.

Ye but constantly excluding and including groups in the settings is insanely cumbersome. At that point auto tagging and excluding tags might be easier

Use the group selector instead, it knows which group you’ve selected the last time, so it’s done with few keystrokes.

Exclude

-- Exclude group from search (via group selector)

tell application id "DNtp"
	try
		set theGroup to display group selector "Exclude from search:"
		set exclude from search of theGroup to true
		display notification (name of theGroup as string) with title "Excluded from Search"
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

Include

-- Include group in search (via group selector)

tell application id "DNtp"
	try
		set theGroup to display group selector "Include in search:"
		set exclude from search of theGroup to false
		display notification (name of theGroup as string) with title "Included in Search"
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

That is neat, thank you

Updated scripts. They now refresh the search results so the changed exluded status is directly visible.

Exclude

-- Exclude group from search (via group selector)

property updateSearchResults : true

tell application id "DNtp"
	try
		set theGroup to display group selector "Exclude from search:"
		set exclude from search of theGroup to true
		display notification (name of theGroup as string) with title "Excluded from Search"
		
		if updateSearchResults = true then
			if (exists viewer window 1) then
				set theQuery to (search query of viewer window 1) as string
				if theQuery ≠ "" then
					set search query of viewer window 1 to "_"
					set search query of viewer window 1 to theQuery
				end if
			end if
		end if
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

Include

-- Include group in search (via group selector)

property updateSearchResults : true

tell application id "DNtp"
	try
		set theGroup to display group selector "Include in search:"
		set exclude from search of theGroup to false
		display notification (name of theGroup as string) with title "Included in Search"
		
		if updateSearchResults = true then
			if (exists viewer window 1) then
				set theQuery to (search query of viewer window 1) as string
				if theQuery ≠ "" then
					set search query of viewer window 1 to "_"
					set search query of viewer window 1 to theQuery
				end if
			end if
		end if
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell
1 Like

is this seriously valid applescript? AS never ceases to amaze…

1 Like