9

I think I know my Lightroom pretty well, but I couldn't find a way to create a smart collection that returns photos containing only one given keyword. Just one. Say, all photos containing only the 'foo' keyword, no other keywords.

The only solution I found was:

  1. create a smart collection that returns photos containing that given keyword 'foo',
  2. select all photos and add them to another collection (say 'temp') for backup,
  3. remove the given keyword 'foo' from the photos,
  4. create a smart collection that returns the photos containing no keywords: this should return all the photos that only had the 'foo' keyword before I removed it in the previous step. Unfortunately all photos that had no keywords before step 3 will be returned as well, but that's OK, I don't have such photos.
  5. do something with the photos returned by step 4, then go to the 'temp' collection and add the 'foo' keyword back.

Tedious.

5
  • 1
    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 ;)
    – gerikson
    Jan 15, 2011 at 23:00
  • I racked my brains but I can't figure out a way to do this; the filtering syntax seems too limited. :-\ Jan 16, 2011 at 1:52
  • More digging: It seems that in LR3 there's no way to filter for "contains tags that are not X"; you can only do "does not contain tag X". Without the former, there's no way to achieve what you're looking for. Jan 16, 2011 at 2:50
  • Also there's the obvious missing functionality, "keyword equals X" -- you can find keywords containing X, but if you have keywords "peanut" and "peanut butter" you cannot find only the exact match "peanut".
    – Jason S
    Jan 16, 2011 at 15:59
  • Thanks guys, yes, I came to the same conclusions so far, but I figured I would still ask on photo.se, in case I really missed a ninja-trick. I'll have to write a plugin in my spare-time :) Jan 17, 2011 at 0:31

4 Answers 4

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)

2
  • Yes, you can do that, though I would say the steps I described in my questions are probably simpler, right? Thanks. Jan 22, 2011 at 6:38
  • simpler but manual. I have a running grudge against computer software which forces me to repeatedly run through efforts that it could do automatically.
    – Jason S
    Jan 22, 2011 at 16:39
3

I tried this, in LR 4: keyword contains "mykeyword" AND keyword doesn't contain "abcdfghijklnpqstuvxz"

where the 2nd string is all the letters NOT in "mykeyword"

not perfect, but it's a quick and dirty hack that mostly works.

2
  • This was the least worst option for me. I had to put spaces between the alphabet letters to get this to work.
    – alx9r
    Oct 12, 2015 at 1:11
  • This would get even more tedious than OP's original solution if you've got a situation in which some of these images have lots of keywords other than mykeyword. In that case, you'd have to manually put in all of the keywords that images that have mykeyword also have. Nov 9, 2020 at 21:00
1

all. I've found a way to do this. Not elegant, but it works quite well.

First, go to All Photographs in your catalog and select all of your photos. In the right pane, under Keywording, you will see a text box below Keyword Tags with ALL keywords found (most followed by an asterisk). Copy all of this text and paste it into a text editor.

Now, remove all of the asterisks (I use find/replace to simplify this), as well as the keyword(s) you wish to limit your search to. Once finished, copy all remaining text.

Now, create a smart collection. Add a rule for "Keyword" "Contains" "Single or Multiple Keyword(s) you want to search".

Next, add a rule for "Keyword" "Does not contain" and paste the edited text. Voila. Adobe really should have thought this one through, but it is Adobe...

2
  • 1
    ick. And then have to edit that smart collection every time you add a new keyword. :(
    – cabbey
    Jan 21, 2011 at 7:43
  • 1
    Interesting, unfortunately doesn't work for me, I have a huge number of keywords. Copying and pasting them into a text editor and saving the file leads to a 45 Kb monster. That's a lot of keywords. Lightroom won't let me enter all of them as a smart collection rule. Interesting idea though, thx. Jan 22, 2011 at 6:45
0

In theory you should be able to do this with the "starts with" and "ends with" filters. Basically build it as:

matches ALL  
keyword  starts with  YourOneKeyWord  
keyword  ends with    YourOneKeyWord

But that doesn't seem to be working. :(

2
  • does this work now with lightroom 3.4? i have set up a smart collection using "starts with" and "ends with" "flickr", and it is returning only those photos with exactly "flickr", excluding a photo that i had with the dummy keyword "flickrzzz".
    – rapscalli
    Oct 3, 2011 at 23:33
  • no, even with LR 3.5 this still fails. I'm not sure how but Adobe's definition of "beginsWith" doesn't seem to match the one most folks would use.
    – cabbey
    Oct 12, 2011 at 3:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.