You are here: Foswiki>Tasks Web>Item10722 (05 Mar 2012, PaulHarvey)Edit Attach

Item10722: System.QuerySearch length() awkward for measuring lists

pencil
Priority: Normal
Current State: Confirmed
Released In: n/a
Target Release: minor
Applies To: Engine
Component: SEARCH
Branches:
Reported By: PaulHarvey
Waiting For:
Last Change By: PaulHarvey
Recently I had a format string in a SEARCH that looked like this (links is a many type via registerMETA):
$percntQUERY{\"length('$web.$topic'/links[scope='external'].address\"}$percnt

Which worked fine, except for when there was only one external link on the topic - in that case, QUERY returned the length of the string. So I did this:
$percntQUERY{\"length(('$web.$topic'/links[scope='external'].address), '') - 1\"}$percnt

And that fixed my immediate problem. What I want to know is - do we document this behaviour and work-around - or is there a way to fix it? (I don't have any ideas how it can be fixed, without really geeking up the syntax to be even more painful than this work-around).

Also, I thought we had documented length(), but I can't find it in QuerySearch... if the doc is still missing, we should use this task to add it (and I guess any other undocumented ops/functions?)

-- PaulHarvey - 08 May 2011

I guess one way would be to add a strlen() and keep length() for lists.

-- PaulHarvey - 08 May 2011

Victim of perl's implicit polymorphism here. I originally intended "length" to apply only to strings, but clearly it works on arrays too. Where the parameter is an array, it should always be the length of the array, not the string in the array, so any implicit casting has to be handled.

  • length(11,12,13) should be 3 is 3
  • length 12 should be 2 is 2
  • length (12) should be 1 is 2
  • length '12' should be 2 is 2
  • length((1,2)) should b1 1 is 2

(view using trunk!)

-- CrawfordCurrie - 21 May 2011

Hrm, I agree with all the examples except the last. Shouldn't length((1,2)) be measuring a list, and therefore return 2? I was under the impression that we were flattening lists in QuerySearch, according to my last understanding of QuerySearch doc

-- PaulHarvey - 22 May 2011

Fair point.

-- CrawfordCurrie - 22 May 2011

my 2cents.

I was trying this to do something like QUERY{length('Tasks.Item10722'/ImageList)+1}to increment an index value.

should be 1 is 1

This works on our version for zero length lists.

QUERY{length (%FORMFIELD{topic="Tasks.Item10722" "ImageList"}%) +1}should be 1 is 1

-- PaulAlexander - 05 Mar 2012

Hi Paul,

What about
%QUERY{
  "length(('%BASEWEB%.%BASETOPIC%'/ImageList)) + 1"
}%

-- PaulHarvey - 05 Mar 2012
 

ItemTemplate edit

Summary QuerySearch length() awkward for measuring lists
ReportedBy PaulHarvey
Codebase trunk
SVN Range
AppliesTo Engine
Component SEARCH
Priority Normal
CurrentState Confirmed
WaitingFor
Checkins
TargetRelease minor
ReleasedIn n/a
CheckinsOnBranches
trunkCheckins
Release01x01Checkins
Topic revision: r8 - 05 Mar 2012, PaulHarvey
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy