Searching for untagged permanodes

68 views
Skip to first unread message

Alex Tsui

unread,
Apr 26, 2021, 3:57:01 AM4/26/21
to Perkeep
I have a workflow in mind where (1) I upload a set of photos to perkeep as permanodes, then (2) tag the photos to keep them organized. I'd like to search for all untagged permanodes (i.e. permanodes where the tag attribute does not exist), but I can't seem to figure out how to do it.

My approach is to use a raw query modeled off of this bit of logic I found in perkeep code: https://github.com/perkeep/perkeep/blob/f2e7add71bf7d7fdc0d8d8060171e41c238e166a/app/scanningcabinet/datastore.go#L618-L642

The idea is to find the negation of the set of all permanodes that have at least one nonempty tag attribute. This is the JSON I'm using to find all tagged permanodes, which seems to work:

```
raw:{"permanode":{"attr": "tag", "valueMatches":{"ByteLength":{"Min":1}}}}
```

However, when I try to negate it like so, I don't seem to get any blobs at all:

```
raw:{"op":"not","a":{"permanode":{"attr": "tag","skipHidden":true,"valueMatches":{"ByteLength":{"Min":1}}}}}
```

Is there something I'm doing wrong? I'd appreciate any hints or feedback.

Thanks,

--Alex

Alex Tsui

unread,
May 5, 2021, 1:04:29 AM5/5/21
to Perkeep
Hi,

I've just figured out the answer to my prior question so I thought I'd share it here for anyone interested.

Basically, the reason why I was getting an empty search result was because my logical not operator wasn't properly specified. Here is the way to query untagged permanodes:

```
{"logical": {"op":"not", "a":{"permanode":{"attr": "tag", "valueMatches":{"ByteLength":{"Min":1}}}}}}
```

The top-level key should be "logical", and the value should model a LogicalConstraint.

Now this returns blobs when using `pk search` CLI, but in the UI, an error message appears because non-permanodes are in the result set. So we need to add an additional constraint that only permanodes should be returned:

```
{"logical": {"op":"and", "a":{"permanode":{"anything": true}}, "b":{"logical": {"op":"not", "a":{"permanode":{"attr": "tag", "valueMatches":{"ByteLength":{"Min":1}}}}}}}}
```

Now I wanted to chain this with the "is:image" predicate but it doesn't mix with raw queries, so I had to do this to search all untagged images:

```
{"logical": {"op":"and", "a":{"permanode": {"attr": "camliContent", "valueInSet": {"file": {"isImage": true}}}}, "b":{"logical": {"op":"not", "a":{"permanode":{"attr": "tag", "valueMatches":{"ByteLength":{"Min":1}}}}}}}}
```

I figured out the "is:image" constraint by looking at the source code.

Anyways, I feel like an "is:untagged" predicate would be a handy predicate to support, so I'll see about contributing a PR soon. For now, I can enjoy importing and tagging my photo collection in perkeep :)

Thanks,

--Alex
Reply all
Reply to author
Forward
0 new messages