[Bug 3618] let score clause

http://www.w3.org/Bugs/Public/show_bug.cgi?id=3618

           Summary: let score clause
           Product: XPath / XQuery / XSLT
           Version: Working drafts
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Full Text
        AssignedTo: sihem@research.att.com
        ReportedBy: davidc@nag.co.uk
         QAContact: public-qt-comments@w3.org


section 2.3 says
The let variable may be dropped from the let clause, if the score variable is
present.

and this is more or less the full description of the meaning of this
expression.

I assumed from this that it meant that if the "normal" let variable is not used
in the return clause, it could be dropped, and that this was just a syntactic
simplification, so that

let $x score $s := $input[title ftcontains "foo"]
return
$s

could be equivalently written without the $x as

let score $s := $input[title ftcontains "foo"]
return
$s

however all actual examples of let score in the document so not use a
node-valued expression but rather the full text boolean expression itself.

let score $s := title ftcontains "foo"
return
$s


Could the specification clarify for the let score clause whether the ExprSingle
to the right of the := must be an ftselection and if it may either be an
ftselection or a path expression, what exactly is being scored in either case.

The semantics of the expresion are further expanded in 4.3.2 but again that is
essentially silent on whether fts:score expects a path expression or an
ftselection as its argument.

This question came about trying to use scoring in xpath, where I need to return
the score as a value. To return the score of testing the current node against
"foo" I thought from reading the text that I had to do

let score $s :=.[. ftcontains "foo"] return $s

but the examples suggest that I could do

let score $s := . ftcontains "foo" return $s

but it isn't clear if these are equivalent. Of course as currently defined
neither can be used in XPath so I have to use

for $x score $s in .[. ftcontains "foo"] return $s

which is fairly horrible, and strongly suggests that the currently proposed
syntax for scoring is unsuitable for use in XPath.

It would be much better for XPath (and XQuery) use if there was a function
syntax such as score() which returned the score of the current item (from
wherever it was selected) The spec has some arguments why this is not possible
in as the value would depend on the context but those arguments would apply
equally to position() or xslt's current(), The context would have to hold the
current nodes score as well as it's value. It doesn't mean that score() has to
be a constant as it is a 0-ary function.

That would allow

<xsl:for-each select="/a/b[c ftcontains'x']">
  <xsl:sort select="score()"/>

(I'm using xslt here but any non-xquery binding of xpath would have the same
issues).

I suspect that the WG would have some resistance to revisiting the score syntax
but if the current syntax is kept then at the very least I think that the let
clause should be added back into xpath as extended by full text. Then at least
Xpath would have

<xsl:for-each select="/a/b[c ftcontains 'x']">
  <xsl:sort select="let score $s := c ftcontains 'x' return $s"/>

which is rather verbose and repetitive but much better than the current

<xsl:for-each select="/a/b[c ftcontains 'x']">
  <xsl:sort select="for $x score $s in .[c ftcontains 'x'] return $s"/>

See also 

David
see also the related bug #3596 and the earlier thread on qt-comments starting
http://lists.w3.org/Archives/Public/public-qt-comments/2006Aug/0081.html

Received on Wednesday, 23 August 2006 10:10:21 UTC