1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-16 23:02:26 +03:00

Fixes for tcl list generation in fts5_test().

FossilOrigin-Name: c1f9a4b76c0bbc1ef9f6cdb5d62aa5d536fdf38e
This commit is contained in:
dan
2014-07-16 20:07:59 +00:00
parent 9cfd51f587
commit 18689f1bd4
4 changed files with 62 additions and 67 deletions

View File

@@ -137,42 +137,6 @@ do_test 1.1 {
}
} {}
proc phrasematch {phrase value} {
if {[string first $phrase $value]>=0} { return 1 }
return 0
}
# Usage:
#
proc nearmatch {nNear phraselist value} {
set nPhrase [llength $phraselist]
set phraselist [string tolower $phraselist]
set value [string tolower $value]
if {$nPhrase==1} {
set bMatch [phrasematch [lindex $phraselist 0] $value]
} else {
set nValue [llength $value]
if {$nNear >= $nValue} {set nNear [expr $nValue-1]}
for {set i $nNear} {$i < $nValue} {incr i} {
set bMatch 1
foreach phrase $phraselist {
set iMin [expr $i - $nNear - [llength $phrase]]
set iMax [expr $i - 1 + [llength $phrase]]
set subdoc [lrange $value $iMin $iMax]
if {![phrasematch $phrase $subdoc]} {
set bMatch 0
break
}
}
if {$bMatch} break
}
}
return $bMatch
}
# Usage:
#
# poslist aCol ?-near N? ?-col C? -- phrase1 phrase2...
@@ -243,6 +207,7 @@ proc poslist {aCol args} {
lappend res $plist
}
#puts $res
return $res
}
@@ -284,9 +249,9 @@ proc matchdata {bPos expr {bAsc 0}} {
set rowres [list]
foreach phrase $N {
set cmd "poslist [string range $phrase 9 end-1]"
lappend rowres [eval $cmd]
set pos [eval $cmd]
set rowres [concat $rowres $pos]
}
if {[string first "\{" $rowres]<0} { set rowres "{{$rowres}}" }
lappend res [list $id $rowres]
} else {
lappend res $id
@@ -303,7 +268,13 @@ proc matchdata {bPos expr {bAsc 0}} {
return [concat {*}$res]
}
#
# End of test code
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
# Test phrase queries.
#
foreach {tn phrase} {
1 "o"
2 "b q"
@@ -316,7 +287,6 @@ foreach {tn phrase} {
9 "no"
10 "L O O L V V K"
} {
set expr "\"$phrase\""
set res [matchdata 1 $expr]
@@ -325,20 +295,24 @@ foreach {tn phrase} {
} $res
}
# Test the "nearmatch" commnad.
#-------------------------------------------------------------------------
# Test some AND and OR queries.
#
do_test 2.0 { nearmatch 2 {a b} {a x x b} } 1
do_test 2.1 { nearmatch 2 {b a} {a x x b} } 1
do_test 2.2 { nearmatch 1 {b a} {a x x b} } 0
do_test 2.3 { nearmatch 1 {"a b" "c d"} {x x a b x c d} } 1
do_test 2.4 { nearmatch 1 {"a b" "c d"} {x a b x x c d} } 0
do_test 2.5 { nearmatch 400 {a b} {a x x b} } 1
do_test 2.6 { nearmatch 0 {a} {a x x b} } 1
do_test 2.7 { nearmatch 0 {b} {a x x b} } 1
foreach {tn expr} {
1 "a AND b"
2 "a+b AND c"
3 "d+c AND u"
4 "d+c AND u+d"
} {
set res [matchdata 1 $expr]
do_execsql_test 2.1.$tn.[llength $res] {
SELECT rowid, fts5_test(xx, 'poslist') FROM xx WHERE xx match $expr
} $res
}
do_test 2.8 { poslist {{a b c}} -- a } {0.0}
do_test 2.9 { poslist {{a b c}} -- c } {0.2}
do_test 2.1 { poslist {{a b c}} -- a } {0.0}
do_test 2.2 { poslist {{a b c}} -- c } {0.2}
foreach {tn expr tclexpr} {
1 {a b} {[N $x -- {a}] && [N $x -- {b}]}