Paris

by Jon

submit your photo


Hall of Fame
View past winners from this year

Please participate in Meta
and help us grow.

Take the 2-minute tour ×
Photography Stack Exchange is a question and answer site for professional, enthusiast and amateur photographers. It's 100% free, no registration required.

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.

share|improve this question
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 '11 at 23:00
    
I racked my brains but I can't figure out a way to do this; the filtering syntax seems too limited. :-\ –  Craig Walker Jan 16 '11 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. –  Craig Walker Jan 16 '11 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 '11 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 :) –  sebastien.b Jan 17 '11 at 0:31

4 Answers 4

@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)

share|improve this answer
    
Thanks for this info! –  gerikson Jan 19 '11 at 21:05
    
Yes, you can do that, though I would say the steps I described in my questions are probably simpler, right? Thanks. –  sebastien.b Jan 22 '11 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 '11 at 16:39

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.

share|improve this answer

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...

share|improve this answer
    
ick. And then have to edit that smart collection every time you add a new keyword. :( –  cabbey Jan 21 '11 at 7:43
    
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. –  sebastien.b Jan 22 '11 at 6:45

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. :(

share|improve this answer
    
Yes, I had tried that, not working. –  sebastien.b Jan 22 '11 at 6:38
    
I pinged someone on the LR team, we'll see if they stop by with any wisdom for us. –  cabbey Jan 22 '11 at 18:38
    
Thx. I would have sooooooo many question to anyone on the LR team :) The Flickr Publish service drives me nuts. –  sebastien.b Jan 24 '11 at 19:17
    
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 '11 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 '11 at 3:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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