SQLite

Check-in [92618c1463]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add tests for FTS ^ searches and matchinfo().
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | fts4-content
Files: files | file ages | folders
SHA1: 92618c1463fb304cf8057d082b2c7096152dff27
User & Date: dan 2011-10-19 10:18:01.912
Context
2011-10-19
11:57
Change the way ^ tokens work in FTS so that the filtering is done as part of reading the FTS index instead of waiting until an entire doclist has been retrieved and then filtering it. (check-in: 9b58c59eb4 user: dan tags: fts4-content)
10:18
Add tests for FTS ^ searches and matchinfo(). (check-in: 92618c1463 user: dan tags: fts4-content)
09:40
Fix a problem in FTS to do with ^ tokens and the snippet() function. (check-in: 2c03b24f4c user: dan tags: fts4-content)
Changes
Unified Diff Ignore Whitespace Patch
Changes to test/fts3first.test.
21
22
23
24
25
26
27








28
29
30
31
32
33
34
proc lreverse {L} {
  set res [list]
  for {set ii [expr [llength $L]-1]} {$ii>=0} {incr ii -1} {
    lappend res [lindex $L $ii]
  }
  set res
}









do_execsql_test 1.0 {
  CREATE VIRTUAL TABLE x1 USING FTS4(a, b, c);
  INSERT INTO x1(docid,a,b,c) VALUES(0, 'K H D S T', 'V M N Y K', 'S Z N Q S');
  INSERT INTO x1(docid,a,b,c) VALUES(1, 'K N J L W', 'S Z W J Q', 'D U W S E');
  INSERT INTO x1(docid,a,b,c) VALUES(2, 'B P M O I', 'R P H W S', 'R J L L E');
  INSERT INTO x1(docid,a,b,c) VALUES(3, 'U R Q M L', 'M J K A V', 'Q W J T J');







>
>
>
>
>
>
>
>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
proc lreverse {L} {
  set res [list]
  for {set ii [expr [llength $L]-1]} {$ii>=0} {incr ii -1} {
    lappend res [lindex $L $ii]
  }
  set res
}

proc mit {blob} {
  set scan(littleEndian) i*
  set scan(bigEndian) I*
  binary scan $blob $scan($::tcl_platform(byteOrder)) r
  return $r
}
db func mit mit

do_execsql_test 1.0 {
  CREATE VIRTUAL TABLE x1 USING FTS4(a, b, c);
  INSERT INTO x1(docid,a,b,c) VALUES(0, 'K H D S T', 'V M N Y K', 'S Z N Q S');
  INSERT INTO x1(docid,a,b,c) VALUES(1, 'K N J L W', 'S Z W J Q', 'D U W S E');
  INSERT INTO x1(docid,a,b,c) VALUES(2, 'B P M O I', 'R P H W S', 'R J L L E');
  INSERT INTO x1(docid,a,b,c) VALUES(3, 'U R Q M L', 'M J K A V', 'Q W J T J');
50
51
52
53
54
55
56


57
58
59
60
61
62
63
  INSERT INTO x1(docid,a,b,c) VALUES(19, 'T R Y P Y', 'N V Y B X', 'L Z T N T');

  CREATE VIRTUAL TABLE x2 USING FTS4(a, b, c, order=DESC);
  INSERT INTO x2(docid, a, b, c) SELECT docid, a, b, c FROM x1;
}




foreach x {1 2} {
  foreach {tn match res} {
    1  "^K"              {0 1 14}
    2  "^S"              {0 1 14}
    3  "^W"              {9 15 17}
    4  "^J"              {}
    5  "^E"              {12}







>
>







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  INSERT INTO x1(docid,a,b,c) VALUES(19, 'T R Y P Y', 'N V Y B X', 'L Z T N T');

  CREATE VIRTUAL TABLE x2 USING FTS4(a, b, c, order=DESC);
  INSERT INTO x2(docid, a, b, c) SELECT docid, a, b, c FROM x1;
}


# Test queries.
#
foreach x {1 2} {
  foreach {tn match res} {
    1  "^K"              {0 1 14}
    2  "^S"              {0 1 14}
    3  "^W"              {9 15 17}
    4  "^J"              {}
    5  "^E"              {12}
78
79
80
81
82
83
84


85
86
87
88
89
90
91
92
93
94

95
96
97
98
99





























100

  do_execsql_test 1.$x.[expr $tn+1] { 
    INSERT INTO x1(x1) VALUES('optimize');
    INSERT INTO x2(x2) VALUES('optimize');
  } {}
}



foreach {tn match res} {
  1  {^K}    {{[K] H D S T} {[K] N J L W} {[K] H A B L}}
  2  {^X}    {{[X] Y D L S} {[X] J P K R} {[X] S B X Y}}
  3  {^X Y}  {{[X] [Y] D L S} {D [Y] P O I...[X] J P K R} {[X] S B X [Y]}}
} {
  set rev [lreverse $res]

  do_execsql_test 1.3.$tn.1 {
    SELECT snippet(x1, '[', ']', '...') FROM x1 WHERE x1 MATCH $match
  } $res

  do_execsql_test 1.3.$tn.2 {
    SELECT snippet(x2, '[', ']', '...') FROM x2 WHERE x2 MATCH $match
  } $rev
}






























finish_test







>
>










>





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

  do_execsql_test 1.$x.[expr $tn+1] { 
    INSERT INTO x1(x1) VALUES('optimize');
    INSERT INTO x2(x2) VALUES('optimize');
  } {}
}

# Test the snippet() function.
#
foreach {tn match res} {
  1  {^K}    {{[K] H D S T} {[K] N J L W} {[K] H A B L}}
  2  {^X}    {{[X] Y D L S} {[X] J P K R} {[X] S B X Y}}
  3  {^X Y}  {{[X] [Y] D L S} {D [Y] P O I...[X] J P K R} {[X] S B X [Y]}}
} {
  set rev [lreverse $res]

  do_execsql_test 1.3.$tn.1 {
    SELECT snippet(x1, '[', ']', '...') FROM x1 WHERE x1 MATCH $match
  } $res

  do_execsql_test 1.3.$tn.2 {
    SELECT snippet(x2, '[', ']', '...') FROM x2 WHERE x2 MATCH $match
  } $rev
}

# Test matchinfo().
#
foreach {tn match res} {
  1  {^K}    {
                {1 3 3 0 0 0 0 0 0}
                {1 3 3 0 0 0 0 0 0}
                {1 3 3 0 0 0 0 0 0}
             }
  2  {^X}    {
                {0 1 1 0 1 1 1 2 2}
                {0 1 1 1 1 1 0 2 2}
                {1 1 1 0 1 1 1 2 2}
             }
  3  {^X Y}  {
                {0 1 1 0 1 1 1 2 2 0 6 5 0 5 4 1 4 4} 
                {0 1 1 1 1 1 0 2 2 1 6 5 0 5 4 0 4 4} 
                {1 1 1 0 1 1 1 2 2 1 6 5 0 5 4 1 4 4}
             }
} {
  set rev [lreverse $res]

  do_execsql_test 1.3.$tn.1 {
    SELECT mit(matchinfo(x1, 'x')) FROM x1 WHERE x1 MATCH $match
  } $res
  do_execsql_test 1.3.$tn.2 {
    SELECT mit(matchinfo(x2, 'x')) FROM x2 WHERE x2 MATCH $match
  } $rev
}

finish_test