OLD | NEW |
1 # 2009 January 1 | 1 # 2009 January 1 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #************************************************************************* | 10 #************************************************************************* |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 115 } |
116 | 116 |
117 proc balanced_andor_tree {nEntry} { | 117 proc balanced_andor_tree {nEntry} { |
118 set tree [balanced_exprtree_structure $nEntry] | 118 set tree [balanced_exprtree_structure $nEntry] |
119 set node "{[balanced_and_tree $nEntry]}" | 119 set node "{[balanced_and_tree $nEntry]}" |
120 regsub -all AND $node OR node | 120 regsub -all AND $node OR node |
121 regsub -all xxx $tree $node tree | 121 regsub -all xxx $tree $node tree |
122 return $tree | 122 return $tree |
123 } | 123 } |
124 | 124 |
| 125 if 1 { |
| 126 |
125 # Test that queries like "1 AND 2 AND 3 AND 4..." are transformed to | 127 # Test that queries like "1 AND 2 AND 3 AND 4..." are transformed to |
126 # balanced trees by FTS. | 128 # balanced trees by FTS. |
127 # | 129 # |
128 for {set i 1} {$i < 100} {incr i} { | 130 for {set i 1} {$i < 100} {incr i} { |
129 do_test 1.$i { | 131 do_test 1.$i { |
130 test_fts3expr2 [random_and_query $i] | 132 test_fts3expr2 [random_and_query $i] |
131 } [balanced_and_tree $i] | 133 } [balanced_and_tree $i] |
132 } | 134 } |
133 | 135 |
134 # Same again, except with parenthesis inserted at arbitrary points. | 136 # Same again, except with parenthesis inserted at arbitrary points. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } {1 {Error parsing expression}} | 197 } {1 {Error parsing expression}} |
196 | 198 |
197 set query [random_andor_query 12] | 199 set query [random_andor_query 12] |
198 set result [balanced_andor_tree 12] | 200 set result [balanced_andor_tree 12] |
199 do_faultsim_test fts3expr3-fault-1 -faults oom-* -body { | 201 do_faultsim_test fts3expr3-fault-1 -faults oom-* -body { |
200 test_fts3expr2 $::query | 202 test_fts3expr2 $::query |
201 } -test { | 203 } -test { |
202 faultsim_test_result [list 0 $::result] | 204 faultsim_test_result [list 0 $::result] |
203 } | 205 } |
204 | 206 |
| 207 } |
| 208 |
| 209 #------------------------------------------------------------------- |
| 210 |
| 211 foreach {tn expr res} { |
| 212 1 {1 OR 2 OR 3 OR 4} {OR {OR {P 1} {P 2}} {OR {P 3} {P 4}}} |
| 213 2 {1 OR (2 AND 3 AND 4 AND 5)} |
| 214 {OR {P 1} {AND {AND {P 2} {P 3}} {AND {P 4} {P 5}}}} |
| 215 3 {(2 AND 3 AND 4 AND 5) OR 1} |
| 216 {OR {AND {AND {P 2} {P 3}} {AND {P 4} {P 5}}} {P 1}} |
| 217 |
| 218 4 {1 AND (2 OR 3 OR 4 OR 5)} |
| 219 {AND {P 1} {OR {OR {P 2} {P 3}} {OR {P 4} {P 5}}}} |
| 220 5 {(2 OR 3 OR 4 OR 5) AND 1} |
| 221 {AND {OR {OR {P 2} {P 3}} {OR {P 4} {P 5}}} {P 1}} |
| 222 |
| 223 6 {(2 OR 3 OR 4 OR 5) NOT 1} |
| 224 {NOT {OR {OR {P 2} {P 3}} {OR {P 4} {P 5}}} {P 1}} |
| 225 |
| 226 7 {1 NOT (2 OR 3 OR 4 OR 5)} |
| 227 {NOT {P 1} {OR {OR {P 2} {P 3}} {OR {P 4} {P 5}}}} |
| 228 |
| 229 8 {(1 OR 2 OR 3 OR 4) NOT (5 AND 6 AND 7 AND 8)} |
| 230 {NOT {OR {OR {P 1} {P 2}} {OR {P 3} {P 4}}} {AND {AND {P 5} {P 6}} {AND {P 7
} {P 8}}}} |
| 231 } { |
| 232 do_test 5.1.$tn { |
| 233 test_fts3expr2 $expr |
| 234 } $res |
| 235 } |
| 236 |
205 set sqlite_fts3_enable_parentheses 0 | 237 set sqlite_fts3_enable_parentheses 0 |
206 finish_test | 238 finish_test |
OLD | NEW |