summaryrefslogtreecommitdiffstats
path: root/test/fts3offsets.test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 17:28:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 17:28:19 +0000
commit18657a960e125336f704ea058e25c27bd3900dcb (patch)
tree17b438b680ed45a996d7b59951e6aa34023783f2 /test/fts3offsets.test
parentInitial commit. (diff)
downloadsqlite3-18657a960e125336f704ea058e25c27bd3900dcb.tar.xz
sqlite3-18657a960e125336f704ea058e25c27bd3900dcb.zip
Adding upstream version 3.40.1.upstream/3.40.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/fts3offsets.test')
-rw-r--r--test/fts3offsets.test135
1 files changed, 135 insertions, 0 deletions
diff --git a/test/fts3offsets.test b/test/fts3offsets.test
new file mode 100644
index 0000000..24c339d
--- /dev/null
+++ b/test/fts3offsets.test
@@ -0,0 +1,135 @@
+# 2010 November 02
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# If SQLITE_ENABLE_FTS3 is not defined, omit this file.
+ifcapable !fts3 { finish_test ; return }
+
+set testprefix fts3offsets
+set sqlite_fts3_enable_parentheses 1
+
+proc extract {offsets text} {
+ set res ""
+
+ set off [list]
+ foreach {t i s n} $offsets {
+ lappend off [list $s $n]
+ }
+ set off [lsort -integer -index 0 $off]
+
+ set iOff 0
+ foreach e $off {
+ foreach {s n} $e {}
+ append res [string range $text $iOff $s-1]
+ append res "("
+ append res [string range $text $s [expr $s+$n-1]]
+ append res ")"
+ set iOff [expr $s+$n]
+ }
+ append res [string range $text $iOff end]
+
+ set res
+}
+db func extract extract
+
+
+do_execsql_test 1.1.0 {
+ CREATE VIRTUAL TABLE xx USING fts3(x);
+ INSERT INTO xx VALUES('A x x x B C x x');
+ INSERT INTO xx VALUES('A B C x B x x C');
+ INSERT INTO xx VALUES('A x x B C x x x');
+}
+do_execsql_test 1.1.1 {
+ SELECT oid,extract(offsets(xx), x) FROM xx WHERE xx MATCH 'a OR (b NEAR/1 c)';
+} {
+ 1 {(A) x x x (B) (C) x x}
+ 2 {(A) (B) (C) x (B) x x C}
+ 3 {(A) x x (B) (C) x x x}
+}
+
+do_execsql_test 1.2 {
+ DELETE FROM xx;
+ INSERT INTO xx VALUES('A x x x B C x x');
+ INSERT INTO xx VALUES('A x x C x x x C');
+ INSERT INTO xx VALUES('A x x B C x x x');
+}
+do_execsql_test 1.2.1 {
+ SELECT oid,extract(offsets(xx), x) FROM xx WHERE xx MATCH 'a OR (b NEAR/1 c)';
+} {
+ 1 {(A) x x x (B) (C) x x}
+ 2 {(A) x x C x x x C}
+ 3 {(A) x x (B) (C) x x x}
+}
+
+do_execsql_test 1.3 {
+ DELETE FROM xx;
+ INSERT INTO xx(rowid, x) VALUES(1, 'A B C');
+ INSERT INTO xx(rowid, x) VALUES(2, 'A x');
+ INSERT INTO xx(rowid, x) VALUES(3, 'A B C');
+ INSERT INTO xx(rowid, x) VALUES(4, 'A B C x x x x x x x B');
+ INSERT INTO xx(rowid, x) VALUES(5, 'A x x x x x x x x x C');
+ INSERT INTO xx(rowid, x) VALUES(6, 'A x x x x x x x x x x x B');
+ INSERT INTO xx(rowid, x) VALUES(7, 'A B C');
+}
+do_execsql_test 1.3.1 {
+ SELECT oid,extract(offsets(xx), x) FROM xx WHERE xx MATCH 'a OR (b NEAR/1 c)';
+} {
+ 1 {(A) (B) (C)}
+ 2 {(A) x}
+ 3 {(A) (B) (C)}
+ 4 {(A) (B) (C) x x x x x x x B}
+ 5 {(A) x x x x x x x x x C}
+ 6 {(A) x x x x x x x x x x x B}
+ 7 {(A) (B) (C)}
+}
+
+
+do_execsql_test 1.4 {
+ DELETE FROM xx;
+ INSERT INTO xx(rowid, x) VALUES(7, 'A B C');
+ INSERT INTO xx(rowid, x) VALUES(6, 'A x');
+ INSERT INTO xx(rowid, x) VALUES(5, 'A B C');
+ INSERT INTO xx(rowid, x) VALUES(4, 'A B C x x x x x x x B');
+ INSERT INTO xx(rowid, x) VALUES(3, 'A x x x x x x x x x C');
+ INSERT INTO xx(rowid, x) VALUES(2, 'A x x x x x x x x x x x B');
+ INSERT INTO xx(rowid, x) VALUES(1, 'A B C');
+}
+do_execsql_test 1.4.1 {
+ SELECT oid,extract(offsets(xx), x) FROM xx WHERE xx MATCH 'a OR (b NEAR/1 c)'
+ ORDER BY docid DESC;
+} {
+ 7 {(A) (B) (C)}
+ 6 {(A) x}
+ 5 {(A) (B) (C)}
+ 4 {(A) (B) (C) x x x x x x x B}
+ 3 {(A) x x x x x x x x x C}
+ 2 {(A) x x x x x x x x x x x B}
+ 1 {(A) (B) (C)}
+}
+
+do_execsql_test 1.5.0 {
+ CREATE VIRTUAL TABLE x1 USING fts3(x);
+ INSERT INTO x1 VALUES('A A A');
+ INSERT INTO x1 VALUES('A A A');
+}
+do_execsql_test 1.5.1 {
+ SELECT offsets(x1) FROM x1 WHERE x1 MATCH 'a OR b AND c NEAR d'
+} {
+ {0 0 0 1 0 0 2 1 0 0 4 1}
+ {0 0 0 1 0 0 2 1 0 0 4 1}
+}
+
+
+set sqlite_fts3_enable_parentheses 0
+finish_test