INTERACT FORUM

Please login or register.

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

Author Topic: Expression help please  (Read 1554 times)

leezer3

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1589
Expression help please
« on: February 01, 2011, 01:48:47 pm »

I've run into a little expression trouble :(
Basically, I'm trying to construct a search query for a picky search engine.
Issues:
1. First off, is it possible to get the last item from a listbuild query? Can't see a way off the top of my head. This isn't so important, but would improve the accuracy of my results somewhat. It's not really practicable to pick the nth item, as the position of the last varies between 2 & 5.
2. I'm trying to run replace upon the results of a clean expression. This isn't working; What I've got at the moment looks like this:
=replace((clean(listitem([album],1,/-))), ,+)
From my (bad) knowledge of how the expressions works, I don't see any reason why it shouldn't. The clean expression works on it's own, as does the replace expression.

Cheers

-Leezer-
Logged

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: Expression help please
« Reply #1 on: February 01, 2011, 03:51:44 pm »

1. Yes. For example, to return the last folder in a path:
=ListItem([Filename (path)], Math(ListCount([Filename (path)],\)-1), \)

2. I think you want:
=Replace(Clean(ListItem([Album],1,-)),/ ,+)
Logged

leezer3

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1589
Re: Expression help please
« Reply #2 on: February 01, 2011, 04:25:36 pm »

Thanks :)
Was expecting these to operate more like Javascript or C#, hence the extra brackets error  :D

This is what I'm using it for, in case someone's wondering:
This complete expression is designed to build a query to work with the Library of Congress NLS Voyager system & my prefixing system for complete audiobook series.
In essence, I assign any series of audiobooks a 4-6 digit alphanumeric code which gets appended to the beginning of the album title. This allows me to keep complete series in the correct order both inside MC & more importantly on portable & DLNA devices.
 
I'm using the calculated field zz_searchquery to build a query like this so that it contains the book title free of any codes and the last name of the author:
="replace(clean(listitem([album],1,/-)),/ ,/+)"/+ListItem([Artist], Math(ListCount([Artist],/ )-1), / )
Then I'm passing the results of this to a link that looks like this:
Code: [Select]
<Link version="1.2">
<Item Name="Name">NLS</Item>
<Item Name="Filter"/>
<Item Name="Action">2</Item>
<Item Name="Base URL">http://nlscatalog.loc.gov/cgi-bin/Pwebrecon.cgi</Item>
<Item Name="Search URL">http:////nlscatalog.loc.gov//cgi-bin//Pwebrecon.cgi?Search_Arg=[zz_searchquery]</Item>
</Link>

Unfortunately you seem to have to hit search a second time when the page loads as they're using some silly Javascript sessioning, but it's a useful little link IMHO.

-Leezer-
Logged

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: Expression help please
« Reply #3 on: February 01, 2011, 04:54:39 pm »

You may have other reasons for saving the search term, but you could use the expression directly in the search. For example, I just updated my Discogs track search to use mark_h's handy "no postfix" expression. That removes removes all parenthetical remarks from the track name which, in most cases, will result in a better search.

Code: [Select]
<Link version="1.2">
<Item Name="Name">Discogs</Item>
<Item Name="Filter">[Media Type]=[Audio]</Item>
<Item Name="Action">1</Item>
<Item Name="Base URL">http://www.discogs.com</Item>
<Item Name="Search URL">http:////www.discogs.com//advanced_search?artist=[Artist]&amp;track=if(isequal(left([name],1),(,1),[name],if(isequal(left([name],1),[,1),[name],if(isequal(listcount([name],(),1,5),clean(ListItem([name],0,()),if(isequal(listcount([name],[),1,5),clean(ListItem([name],0,[)),[name])))&amp;btn=Search+Releases&amp;sort=year%2Casc</Item>
</Link>
Logged
Pages: [1]   Go Up