Permalink
Browse files

rank function tested to function as expected

  • Loading branch information...
1 parent 8e8f718 commit 48f84a4592afd97302c6b3c8c187dc5d664f53e4 @coolaj86 committed Jul 21, 2012
Showing with 29 additions and 8 deletions.
  1. +2 −2 Makefile
  2. +2 −2 fts4-rank.c
  3. +21 −2 test-fts4.sql
  4. +4 −2 test-matchinfo.sql
View
@@ -2,11 +2,11 @@ all: linux
#Linux
linux:
- gcc -shared -fPIC -Isqlite3 -o fts4-rank.sqlext fts4-rank.c
+ gcc -Wall -Werror -shared -fPIC -Isqlite3 -o fts4-rank.sqlext fts4-rank.c
#Using GCC on Mac OSX
darwin:
- gcc -bundle -fPIC -Isqlite3 -o fts4-rank.sqlext fts4-rank.c
+ gcc -Wall -Werror -bundle -fPIC -Isqlite3 -o fts4-rank.sqlext fts4-rank.c
win32:
#Microsoft Tools on Windows
View
@@ -37,7 +37,7 @@ SQLITE_EXTENSION_INIT1
** ORDER BY rank(matchinfo(documents), 1.0, 0.5) DESC
*/
static void rankfunc(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal){
- int *aMatchinfo; /* Return value of matchinfo() */
+ unsigned int *aMatchinfo; /* Return value of matchinfo() */
int nCol; /* Number of columns in the table */
int nPhrase; /* Number of phrases in the query */
int iPhrase; /* Current phrase */
@@ -75,7 +75,7 @@ static void rankfunc(sqlite3_context *pCtx, int nVal, sqlite3_value **apVal){
** the hit count and global hit counts for each column are found in
** aPhraseinfo[iCol*3] and aPhraseinfo[iCol*3+1], respectively.
*/
- int *aPhraseinfo = &aMatchinfo[2 + iPhrase*nCol*3];
+ unsigned int *aPhraseinfo = &aMatchinfo[2 + iPhrase*nCol*3];
for(iCol=0; iCol<nCol; iCol++){
int nHitCount = aPhraseinfo[3*iCol];
int nGlobalHitCount = aPhraseinfo[3*iCol+1];
View
@@ -6,12 +6,31 @@ CREATE VIRTUAL TABLE documents USING fts4(title, content);
INSERT INTO documents VALUES('hello world', 'This message is a hello world message.');
INSERT INTO documents VALUES('urgent: serious', 'This mail is seen as a more serious mail');
-SELECT title FROM documents WHERE documents MATCH 'effect* known';
+SELECT title FROM documents WHERE documents MATCH 'message';
+
+/*
+SELECT title FROM documents
+ WHERE documents MATCH 'default transaction'
+ ORDER BY rank(matchinfo(documents)) DESC
+ LIMIT 10 OFFSET 0
+*/
+
+SELECT docid, hex(matchinfo(documents)) AS rank
+ FROM documents
+ WHERE documents MATCH '"serious mail"'
+ ORDER BY rank DESC
+ LIMIT 10 OFFSET 0;
+
+SELECT docid, rank(matchinfo(documents)) AS rank
+ FROM documents
+ WHERE documents MATCH '"serious mail"'
+ ORDER BY rank DESC
+ LIMIT 10 OFFSET 0;
SELECT title FROM documents JOIN (
SELECT docid, rank(matchinfo(documents)) AS rank
FROM documents
- WHERE documents MATCH 'effect* known once'
+ WHERE documents MATCH '"serious mail"'
ORDER BY rank DESC
LIMIT 10 OFFSET 0
) AS ranktable USING(docid)
View
@@ -25,7 +25,8 @@ INSERT INTO t1 VALUES('single request', 'default data');
-- 1 rows).
--
SELECT matchinfo(t1) FROM t1 WHERE t1 MATCH 'default transaction "these semantics"';
--- In order to see the result as a non-blob, hex() must be used
+
+-- the blob appears as an empty string. To view an ascii representation, use hex()
SELECT hex(matchinfo(t1)) FROM t1 WHERE t1 MATCH 'default transaction "these semantics"';
-- The format string for this query is "ns". The output array will therefore
@@ -39,5 +40,6 @@ SELECT hex(matchinfo(t1)) FROM t1 WHERE t1 MATCH 'default transaction "these sem
-- number of rows in the table). The following two values are the lengths
-- of the longest common subsequence of phrase matches in each column.
SELECT matchinfo(t1, 'ns') FROM t1 WHERE t1 MATCH 'default transaction';
--- In order to see the result as a non-blob, hex() must be used
+
+-- the blob appears as an empty string. To view an ascii representation, use hex()
SELECT hex(matchinfo(t1, 'ns') FROM t1 WHERE t1 MATCH 'default transaction';

0 comments on commit 48f84a4

Please sign in to comment.