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 <https://perkeep.org/pkg/search#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 
<https://github.com/perkeep/perkeep/blob/dd14e9ea063054c9230218c2311cea15ba7f9284/pkg/search/predicate.go#L459-L471>
.

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
On Monday, April 26, 2021 at 12:57:01 AM UTC-7 Alex Tsui wrote:

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

-- 
You received this message because you are subscribed to the Google Groups 
"Perkeep" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/perkeep/21203967-bbe5-4878-a552-8f52348f6361n%40googlegroups.com.

Reply via email to