INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Search and Expressions  (Read 1374 times)

JoeBloe

  • Recent member
  • *
  • Posts: 13
Search and Expressions
« on: July 16, 2014, 09:33:33 pm »

I am confused.
I have an expression that I use for determining a TV show's [name]...
Quote
=ifelse(isequal([season],unknown season,8),,compare([season],=,0),[season],isrange(right([season],1),a-z),[season]/ ,isrange([season],1900-2100),[season]/ ,isrange(left([season],1),a-z),[season],IsRange([season],1-99),if(compare(left([season],1),=,0),removeleft([season],1),[season]))ifelse(isequal([episode],unknown episode,8),,IsRange([episode],1-9.9),if(compare(left([episode],1),=,0),[episode]/ ,0[episode]/ ),isequal([episode],-,8),if(compare(length([episode]),<=,4),0[episode]/ ,[episode]/ ),1,[episode]/ )if(isempty([episode title]),[name],[episode title])

when I use that expression to do a search for files that haven't been 'properly named'
Quote
[=isequal([name],=ifelse(isequal([season],unknown season,8),,compare([season],=,0),[season],isrange(right([season],1),a-z),[season]/ ,isrange([season],1900-2100),[season]/ ,isrange(left([season],1),a-z),[season],IsRange([season],1-99),if(compare(left([season],1),=,0),removeleft([season],1),[season]))ifelse(isequal([episode],unknown episode,8),,IsRange([episode],1-9.9),if(compare(left([episode],1),=,0),[episode]/ ,0[episode]/ ),isequal([episode],-,8),if(compare(length([episode]),<=,4),0[episode]/ ,[episode]/ ),1,[episode]/ )if(isempty([episode title]),[name],[episode title]),1)]=0
I come up with either all files or nothing, depending on whether the very last number is 0 or 1 respectively. I even made sure that there were misnamed episodes, but got the same result, all or nothing.

Are there different rules for expressions within searches, am I just missing something simple. PLEASE HELP!!!
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Search and Expressions
« Reply #1 on: July 16, 2014, 10:32:21 pm »

Yes.  The Search expression system is different, in some ways, from the expression system used for calculated fields and columns.  Conceptually, they're different.

For a Query, you're testing each file in the Library, one by one, against an expression and looking for a simple True/False result.  The expression can access any field in the Library, but the output has to be True or False, to decide whether a particular file is included or excluded from the results list.  True or false essentially correlate to 1 or 0.  Though, really it correlates to:

Quote
So long as the query produces a true value (a value of 1), the file will be included.

Everything else is false, or just doesn't work at all.

A field expression (or column) outputs a string.  It is, essentially, a text-replacement system.  If you enter a particular field and you enter =[Field Name] it would just output itself.  But you can use this to transform the contents of a field (amalgamating other fields, etc).

I think you know all of that, but the references here are fairly detailed (thanks to MrC and marko):
http://wiki.jriver.com/index.php/Smartlist_and_Search_-_Rules_and_Modifiers
http://wiki.jriver.com/index.php/Media_Center_expression_language

The easiest way to test a search expression is with a Smartlist, of course.  But while you are perfecting the search you can also easily make an Expression Column and paste the search query there.  So, using your examples, I get:



Obviously no good.

So, if I tweak it so that:

Code: [Select]
=isequal([name],=ifelse(isequal([season],unknown season,8),,compare([season],=,0),[season],isrange(right([season],1),a-z),[season]/ ,isrange([season],1900-2100),[season]/ ,isrange(left([season],1),a-z),[season],IsRange([season],1-99),if(compare(left([season],1),=,0),removeleft([season],1),[season]))ifelse(isequal([episode],unknown episode,8),,IsRange([episode],1-9.9),if(compare(left([episode],1),=,0),[episode]/ ,0[episode]/ ),isequal([episode],-,8),if(compare(length([episode]),<=,4),0[episode]/ ,[episode]/ ),1,[episode]/ )if(isempty([episode title]),[name],[episode title]),1)
I get a nice clean line of zeros in the Expression 2 column.  That means none match the query.  But I still don't think that's what you want.  I see in the above, you have a bunch of "unknown season" and other "default" values.  That expression is so dense that I'm not going to expend the brainpower to figure out exactly what you want, but the idea is this:

You want to: =If(IsEqual([field],expected value,<mode>),1,0)
Or perhaps more likely (depending on your goals): =If(IsEmpty([field],<mode>)1,0)

Another tool that might be handy for this use is FirstNotEmpty, something like:  =If(IsEmpty(FirstNotEmpty([field1], [field2], [field3], 0),1),0,1)
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Search and Expressions
« Reply #2 on: July 16, 2014, 10:41:52 pm »

I should mention that I'm not sure what you're doing with that initial expression, but it looks like you're trying to generate something awfully close to what the built-in TVInfo(SeasonEpisode) expression generates.  Maybe plus the name.  You might want to look at that as well for your original use-case, as it is quite simple, and usually produces a proper output.

I use it to display the Episode info in my Theater View File Info Panel for TV Show episodes.  It works quite well and handles cases "cleanly" where only an [Episode] or [Season] or neither is available (perhaps on purpose, for certain types of content).
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

JoeBloe

  • Recent member
  • *
  • Posts: 13
Re: Search and Expressions
« Reply #3 on: July 18, 2014, 12:15:53 pm »

Thank you for your response glynor.
Alas, the TVInfo(anything) isn't what I'm after. I have lots of ripped extras, bloopers, etc and, let's just say, that the expression works well to format [name] as I want it displayed. It handles the various permutations of field entries I have.

The "empty" functions do not work for my purposes as I am trying to determine if [name] is, or is not, as I wish it to be. [name] is invariably populated with data, just not necessarily what I am after, ergo the search.

I also tried your [=if(isequal([name],<expression>,1),1,0)]=0 idea and got the same result as before...all or nothing, even when I purposefully made sure that one of the files was mis[name]d. Not sure why. That seemed like a very good possible solution.

Maybe I just have to manually search through files to find discrepancies. I was just trying to have an easier way of finding those files that I needed to edit. I suppose I could continually enter my expression for all files since the program will only rename the ones that don't match.

I just hate leaving a problem unsolved. It seems logical to me that comparing a field with the expression to create that field should tell me when they don't.
Logged
Pages: [1]   Go Up