INTERACT FORUM

Please login or register.

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

Author Topic: Expression on list field  (Read 7131 times)

aussie1

  • World Citizen
  • ***
  • Posts: 249
  • nothing more to say...
Expression on list field
« on: March 02, 2016, 12:47:01 pm »

I have a list field called [Styles]. I'm trying to write an expression such that if one of the items in the list contains a certain value return TRUE otherwise return FALSE.

For example, I want an expression that says: If one of the Styles is "Acoustic Blues" Then TRUE Else FALSE.

I've experimented with different expressions, such as
(1)
ifelse( [Styles])=/#Acoustic Blues#/),"TRUE","FALSE") but this does an exact match on the entire styles field and only returns true if there is one item on the list called "Acoustic Blues". I want to return TREE if styles contains an Acoustic Blues value as one of the list items, not when it is equal to Acoustic Blues

(2)
I looked at the ListItem() Expression, but this requires me to specify the position in the list, which is not know and might be different for different tracks.

Suggestions?



Logged

Arindelle

  • Citizen of the Universe
  • *****
  • Posts: 2772
Re: Expression on list field
« Reply #1 on: March 02, 2016, 01:52:16 pm »

hmm just played around with this and I'd like an answer too .. so bump it is :)

Normaly I'd use If and isequal

Code: [Select]
if(isequal([Styles], Acoustic Blues,1),TRUE, FALSE)
works but only if the delimited list field ONLY contains Acoustic Blues eg Acoustic Blues; Delta Blues would turn up false

when creating a rule with the wizard when you want to use "contains" rather than equals you get

Code: [Select]
[Styles]="Acoustic Blues" from which the above example Acoustic Blues; Delta Blues would show up

can't use the double quotes as they are treated as text; escape characters don'ts seem to change anything

so is there away around this? or is there another operator like isequal .... like isincluded? only see isequal and isempty in the wiki
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42373
  • Shoes gone again!
Re: Expression on list field
« Reply #2 on: March 02, 2016, 02:02:13 pm »

Would a new function ListContains(...) do the trick?

It would take a list like a;b;c and something it's searching for.

It would return true or false.

I think it would do case-insensitive searching.

Thoughts?
Logged
Matt Ashland, JRiver Media Center

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42373
  • Shoes gone again!
Re: Expression on list field
« Reply #3 on: March 02, 2016, 02:07:12 pm »

Thinking a little more, it might be good to make it take three parameters:
list: the list to search
search: what it's searching for
int nFlags: flags for searching (set to one for case sensitive matching)

That way case insensitivity could be optional by changing nFlags.  And we could do other fancy search matching things there eventually.

I think we could make nFlags default to something so it was optional.
Logged
Matt Ashland, JRiver Media Center

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Expression on list field
« Reply #4 on: March 02, 2016, 02:17:10 pm »

This sounds amazing.
Logged
"Some cultures are defined by their relationship to cheese."

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

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42373
  • Shoes gone again!
Re: Expression on list field
« Reply #5 on: March 02, 2016, 02:24:14 pm »

Coming next build:
NEW: Added a ListContains(...) expression function.
Logged
Matt Ashland, JRiver Media Center

aussie1

  • World Citizen
  • ***
  • Posts: 249
  • nothing more to say...
Re: Expression on list field
« Reply #6 on: March 02, 2016, 03:25:45 pm »

This is another illustration of the great support and responsiveness of JRiver!  Thanks.

ListContains(...) is a good addition.

One thing to note. There is a difference between just searching the entire string in the list field for a text match and searching the ; denominated list for a particular value.

Using my example above, suppose I have two records with the following list field values:
Track 1:   Acoustic; Acoustic Blues
Track 2:   Acoustic Blues; Jazz

If you just search for the occurrence of a string it might not bring back my desired result:

ListContains(Acoustic) would bring back both tracks. There are use cases when this might be desirable. But in my use case, I would want it to only bring back Track 1.




Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42373
  • Shoes gone again!
Re: Expression on list field
« Reply #7 on: March 02, 2016, 03:47:14 pm »

Hey, we can handle that!

I'll make a "2" for the flags mean it needs to contain the full string when it matches.
Logged
Matt Ashland, JRiver Media Center

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Expression on list field
« Reply #8 on: March 02, 2016, 04:20:04 pm »

For simple substring searching of a List type field, regex() works just fine:

Code: [Select]
if(regex([Styles],/#rock#/,0,0),ROCK,Nope)
Outputs ROCK if rock is a substring of the list field [Styles].  Now, trying to make it ONLY match Rock and not Blues Rock, or Rock and Roll is tricky.  I haven't figured out an easy way to do that.

Brian.
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9139
Re: Expression on list field
« Reply #9 on: March 02, 2016, 04:23:47 pm »

if(isequal([styles],accoustic,8),yes,no)

also performs a substring search on [styles]

Toucan

  • Recent member
  • *
  • Posts: 12
Re: Expression on list field
« Reply #10 on: March 02, 2016, 05:20:22 pm »

Just a tuppence from the UK, but this is why I love JRiver. Such quick changes; so responsive and I wish my clients could react as fast. This is what I call agile.

I might never use this function, but I'm glad it's there.

I'm just shaking my head and laughing. Keep doing what you're doing.
Logged

Arindelle

  • Citizen of the Universe
  • *****
  • Posts: 2772
Re: Expression on list field
« Reply #11 on: March 03, 2016, 03:01:22 am »

Thinking a little more, it might be good to make it take three parameters:
list: the list to search
search: what it's searching for
int nFlags: flags for searching (set to one for case sensitive matching)

That way case insensitivity could be optional by changing nFlags.  And we could do other fancy search matching things there eventually.

I think we could make nFlags default to something so it was optional.

hmm I've been messing around for a couple of years to have a "taxonomy" in my genre structure (I have 15 top genres, about 100 sub-genres and about 500 styles or sub-subgenres if you will) Lots of them cross over; all usedelimited list fields

so lets say I have Artist 1 [Genre]=Country;Pop/Rock SubGenre1=Alt. Country; Blues-Rock; Southern Rock
Artist 2 [Genre] Pop/Rock; Country [SubGenre1]=Indie Pop&Folk: Alt. Country

When I filter/drill-down for Country at present all of these 4 subgenres are going to show up split like they should - but they are not all country genres ...I'd like to see only Alt. Country showing up under Country and Blues-Rock, Southern Rock, and Indie Pop&Folk to show up under Pop/Rock.

I I understand correctly, with this new function I could make it return "Country" if  IF(ListContains([Genres], Alt. Country), Country, EMPTY)

but as I have 15 Country genres could they all be put in one expression? like IF(ListContains([Genres], Alt. Country, Trad. Country, Bluegrass, Country-Pop, etc. ...), Country, EMPTY)

Now if I filter on Country I get 20 or so genres when I would like to see only 12, Pop/Rock I get 44 genres when I should have only 20 or so.

If by adding an ifelse(...) could this be further nested in theory? or I'm I being delusional (Mr C was trying to help me using listbuild and creating multiple lists for my 15 top genres but with 124 sub-genres, this got to be lets say unwieldy.) ;D

if(isequal([styles],accoustic,8),yes,no)

also performs a substring search on [styles]
is the 8 a sub string search? man missed that. Is there anything explaining the flags 0,1,8 etc? can they used for all all functions
Logged

aussie1

  • World Citizen
  • ***
  • Posts: 249
  • nothing more to say...
Re: Expression on list field
« Reply #12 on: March 04, 2016, 03:54:36 am »

Arindelle hit on my objective for asking this question. I'm trying to build a three-level genre/subgenre/style taxonomy as well. My tree is not solely one-to-one relationships. A single style could roll up into multiple subgenres.

Simple in a fully relational database, a basic dimensional model, probably de-normalized to be a single dimension table containing all three fields and a unique key that would be stored in the track (fact) record. The dim table would contain one record for each possible combination of genre, subgenre, and style.




Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Expression on list field
« Reply #13 on: March 04, 2016, 06:04:07 am »

Hey, we can handle that!

I'll make a "2" for the flags mean it needs to contain the full string when it matches.

this totally rocks, i have a lot of uses for searching a list field.  thanks as always Matt
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Expression on list field
« Reply #14 on: March 04, 2016, 06:50:04 am »

is the 8 a sub string search? man missed that. Is there anything explaining the flags 0,1,8 etc? can they used for all all functions

Yes. 8 is substring search.

See:
http://wiki.jriver.com/index.php/IsEqual()

Many of the functions have their own parameter values. They're documented. See:
http://wiki.jriver.com/index.php/Expression_Language#Function_Index
Logged
"Some cultures are defined by their relationship to cheese."

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

Arindelle

  • Citizen of the Universe
  • *****
  • Posts: 2772
Re: Expression on list field
« Reply #15 on: March 08, 2016, 01:18:42 pm »

Yes. 8 is substring search.

See:
http://wiki.jriver.com/index.php/IsEqual()

Many of the functions have their own parameter values. They're documented. See:
http://wiki.jriver.com/index.php/Expression_Language#Function_Index
Thanks for the confirm, and certainly am familiar with the links. Are you saying that these flags don't mean the same thing like 8 is always a substring search, but is actually used differently for each function? Not sure what you mean by fully documented otherwise??

Arindelle hit on my objective for asking this question. I'm trying to build a three-level genre/subgenre/style taxonomy as well. My tree is not solely one-to-one relationships. A single style could roll up into multiple subgenres.
as the library is not relational, per se, one benefit is that you can filter in both directions.  A taxonomic layout is cool top to bottom drilling down.  But you want to be able to "drill up"from the lowest genre too.

Well this new function might be able to address this, so thanks Matt! To a degree though, as I think I'm going to have to combine lists anyways.  I'm thinking about creating a custom delimited field calculated using this function which could then replace for display my top genre.  For standard veiws I don't care so much, but for theater and remote views that might just work
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Expression on list field
« Reply #16 on: March 12, 2016, 01:56:39 pm »

Are you saying that these flags don't mean the same thing like 8 is always a substring search, but is actually used differently for each function?

Correct.

Take IsEmpty(), IsEqual(), and FixCase() for example. Each of these have a mode argument.

A value of 1 for IsEmpty()'s mode argument does: Numerical test (field must be empty, or contain 0 to get a positive result)
A value of 1 for IsEqual()'s mode argument does: Case-insensitive string compare for equality
A value of 1 for FixCase()'s mode argument does: Capitalizes the initial letter of all words in the provided string

Each function has its own completely independent set of arguments. In some cases, they may match each other (usually when the function is simple) to make them easier to use, but that's incidental. Each function documented in the wiki includes a description of the applicable arguments, and in the case of a mode argument like those above, provides a table explaining what each numeric flag does.

Unless we missed any. If you find any that aren't right, pop a note in the Wiki Updates thread.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/
Pages: [1]   Go Up