Can Lightroom Smart Collections find photos that have only one specific keyword?
Asked 1/15/2011
1 views
2 answers
0
In Lightroom, I want a Smart Collection that matches photos tagged with one specific keyword and no others. For example, find photos that have the keyword “foo” and no additional keywords at all.
I couldn’t find a direct rule for “has exactly this keyword and nothing else.” Is there any built-in way to do this with Smart Collections, or is there a practical workaround?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
15y ago
2 Answers
7
@gerikson:
I'm sorry, I don't have an answer, I just want to say I wish more tools accepted real SQL as a query language ;)
But technically you can do this. The Lightroom catalog is an SQLite database -- try browsing it with Firefox's SQLite Manager addon, and you'll see it's pretty simple.
You could do this in Lua by writing an extension -- alas, I haven't gone through that step so I'm not sure how to do it.
If you don't need it to be an auto-updating collection the way smart collections work, but rather can deal with running a script every now and then, you could write an external tool to query the SQLite database the way you want, and create a smart collection xml file explicitly including the particular photos in question, and import that into Lightroom. (I needed to do this last bit myself -- see this question)
I just tried this select query and it works great:
SELECT
img.id_local AS imageID,
kwdef.name AS keyword,
img.rootFile AS fileID,
files.originalFilename
FROM AgLibraryKeywordImage kwimg
JOIN Adobe_images img
ON img.id_local = kwimg.image
JOIN AgLibraryFile files
ON img.rootFile = files.id_local
JOIN AgLibraryKeyword kwdef
ON kwdef.id_local = kwimg.tag
GROUP BY kwimg.image
HAVING COUNT(*)=1
AND kwdef.name = ?
where you should either replace the ? with a keyword name (e.g. 'foo') or execute as a prepared statement. The GROUP BY clause does the magic: this groups the results by image, HAVING COUNT(*)=1 tells SQL to limit its output to images having 1 record.
This query probably won't work quite right for images that have stacks, in which case it needs to be modified to ensure all the JOINs are one-to-one (except for the keyword-image table)
Originally by user530. Source · Licensed CC BY-SA 4.0
user530
15y ago
0
Generated from our catalog & community — verify before relying on it.
Lightroom doesn’t appear to offer a direct Smart Collection rule for “has exactly this one keyword and no others.” Based on the community replies, the practical workaround is to combine:
- Keyword contains: your target keyword
- Keyword does not contain: a pasted list of all other keywords in your catalog
How to do it:
- In All Photographs, select all photos.
- In the Keywording panel, copy the full list of catalog keywords.
- Paste into a text editor and remove:
- asterisks
- the keyword(s) you want to allow
- Create a Smart Collection with:
- Keyword contains
foo - Keyword does not contain
[all remaining keywords]
- Keyword contains
This is a workaround, not a perfect feature. A rougher hack mentioned was excluding a string made from letters not in the target keyword, but that’s less reliable. More advanced options like querying the Lightroom catalog database or writing a plugin/script were mentioned, but those are external solutions rather than built-in Lightroom behavior.
Recommended products
UniqueBot
AI15y ago
Your Answer
Related Questions
How do I add multiple keywords to photos in Lightroom without them disappearing from the 'Without Keywords' collection?
How can I make Lightroom Smart Collections match exact people names?
How can I build Lightroom Smart Collections for hierarchical keywords like “shutterstock > accepted”?
How can I find photos that aren’t in any Lightroom 5 collection?
How can I find photos tagged with only a parent keyword in Lightroom?