genres list not searchable with OR operator?

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
dgnrt3
Posts: 26
Joined: 21 Apr 2023, 19:58

genres list not searchable with OR operator?

Post by dgnrt3 »

Hi all,

maybe I'm overseeing something here but is there a reason why genres is not searchable with an OR (||) operator? Have searched the forums for similar use cases but couldnt find a fitting one and also experimented with .match() and similar things but It feels like I'm smashing my head against a brick wall. Any help is greatly appreciated.

What im trying to do: Filter out titles with genres containing "Soap" or "Reality".

What i tried:

Groovy: Select all

{genres.contains(/Reality||Soap/) ? 1 : 2}
Stallone: 2
GZSZ: 2
Mr. Robot: 2

Groovy: Select all

{'Reality'||'Soap' in genres ? 1 : 2}
Stallone: 1
GZSZ: 1
Mr. Robot: 1

Groovy: Select all

{genres =~ /Reality||Soap/ ? 1 : 2}
Stallone: 1
GZSZ: 1
Mr. Robot: 1

Groovy: Select all

{genres == 'Reality'||'Soap' ? 1 : 2}
Stallone: 1
GZSZ: 1
Mr. Robot: 1
.

Console Output: Select all

n	The Family Stallone
y	2023
s	1
e	7
s00e00	S01E07
t	Green Light Fight
genre	Reality
genres	[Reality]
.

Console Output: Select all

n	Gute Zeiten, schlechte Zeiten
y	1992
s	1
e	7
s00e00	S01E07
genre	Drama
genres	[Drama, Soap]
.

Console Output: Select all

n	Mr. Robot
y	2015
s	1
e	10
s00e00	S01E10
genre	Crime
genres	[Crime, Drama]
User avatar
rednoah
The Source
Posts: 23449
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: genres list not searchable with OR operator?

Post by rednoah »

:!: Your code is semantically incorrect:

Format: Select all

{ genres.contains(/Reality||Soap/) ? 1 : 2 }
This code will check if the list of genres contains a genre literally "Reality||Soap" which of course it does not, thus always false.


:!: Your code is semantically incorrect:

Format: Select all

{ genres =~ /Reality||Soap/ ? 1 : 2 }
This expression will match "Reality", "" and "Soap", and "" (i.e. nothing; empty String) matches everything, because every something contains nothing, thus always true.


:idea: Here's code that matches "Reality" or "Soap" correctly:

Format: Select all

{ genres =~ /Reality|Soap/ ? 'SOAP' : 'NO SOAP' }
:arrow: You'll want to use https://regexr.com/ to learn and prototype custom regex patterns.



:!: This code is a bad idea, because who knows operator precedence? Is it (a == b) || c or a == (b || c)? Actually, doesn't matter, neither interpretation does what you meant to do:

Groovy: Select all

{genres == 'Reality'||'Soap' ? 1 : 2}
:idea: Here's the logical OR condition you're trying to express:

Groovy: Select all

{ genres.contains('Reality') ||  genres.contains('Soap') ? 'SOAP' : 'NO SOAP' }
:idea: Please read the FAQ and How to Request Help.
dgnrt3
Posts: 26
Joined: 21 Apr 2023, 19:58

Re: genres list not searchable with OR operator?

Post by dgnrt3 »

ufff....now you're explaining it it makes so much sense lol
Thanks for helping me out...wasnt my brightest day lmao
Post Reply