Changes

Jump to navigation Jump to search
67 bytes added ,  15:04, 14 January 2021
<syntaxhighlight lang="xquery">
(: Score values: 1 0.62 0.45 :)
for $text score $score in ("A", "A B", "A B C")[. let score $score := $text contains text "A"]
order by $score descending
return <hit score='{ format-number($score, "0.00") }'>{ $text }</hit>
</syntaxhighlight>
This simple approach has proven to consistently deliver good results, and in particular when little is known about the structure of the queried XML documents.
Please note that scores will only Scoring values can be computed if a parent expression requests themfurther processed to compute custom values:
<syntaxhighlight lang="xquery">
let $terms := (: Computes and returns 'a scoring value. :', 'b')let score $score scores := ft:score($terms ! ('a b c' contains text { . }))return avg($scores)<x/syntaxhighlight>Hello Universe Please note that scoring propagation was removed with {{Mark|Version 9.5}}. The following expressions will now yield {{Code|0}}: <syntaxhighlight lang="xquery">for $n score $s in db:open('factbook')/x> /religions[text() contains text "hello"'orthodox']return $scores,
(: No scoring value will be computed here. :)let $result string := <x>Hello Universe</x> contains text "hello"'a b'let return ft:score ($score := string contains text 'a' and $resultreturn $scorestring contains text 'b')
</syntaxhighlight>
Scores will be propagated Scoring is still supported within full-text expressions and by the {{CodeFunction|and}} and {{CodeFull-Text|orft:search}} expressions and in predicates. In the following query, all returned scores are equal:
<syntaxhighlight lang="xquery">
let for $text := "A B C"let n score $s1 s in ft:= search('factbook', 'orthodox')return $text contains text "A" ftand "B C"s,let score $s2 := $text contains text "A" ftand "B C"let score $s3 string := $text contains text "A" and $text contains text "B C"'a b'let score $s4 return ft:= $text contains text "A" or $text contains text "B C"let score ($s5 := $text[. string contains text "A"][. contains text "B C"]return ($s1, $s2, $s3, $s4, $s5'a' ftand 'b')
</syntaxhighlight>
 
The reason for removing the scoring propagation was that the storage of scoring values required additional memory, even if scoring is not required.
==Thesaurus==
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu