OLD | NEW |
1 /* | 1 /* |
2 ** 2011 Jun 13 | 2 ** 2011 Jun 13 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
11 ****************************************************************************** | 11 ****************************************************************************** |
12 ** | 12 ** |
13 ** This file is not part of the production FTS code. It is only used for | 13 ** This file is not part of the production FTS code. It is only used for |
14 ** testing. It contains a Tcl command that can be used to test if a document | 14 ** testing. It contains a Tcl command that can be used to test if a document |
15 ** matches an FTS NEAR expression. | 15 ** matches an FTS NEAR expression. |
16 ** | 16 ** |
17 ** As of March 2012, it also contains a version 1 tokenizer used for testing | 17 ** As of March 2012, it also contains a version 1 tokenizer used for testing |
18 ** that the sqlite3_tokenizer_module.xLanguage() method is invoked correctly. | 18 ** that the sqlite3_tokenizer_module.xLanguage() method is invoked correctly. |
19 */ | 19 */ |
20 | 20 |
21 #include <tcl.h> | 21 #if defined(INCLUDE_SQLITE_TCL_H) |
| 22 # include "sqlite_tcl.h" |
| 23 #else |
| 24 # include "tcl.h" |
| 25 # ifndef SQLITE_TCLAPI |
| 26 # define SQLITE_TCLAPI |
| 27 # endif |
| 28 #endif |
22 #include <string.h> | 29 #include <string.h> |
23 #include <assert.h> | 30 #include <assert.h> |
24 | 31 |
25 #if defined(SQLITE_TEST) | 32 #if defined(SQLITE_TEST) |
26 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) | 33 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) |
27 | 34 |
28 /* Required so that the "ifdef SQLITE_ENABLE_FTS3" below works */ | 35 /* Required so that the "ifdef SQLITE_ENABLE_FTS3" below works */ |
29 #include "fts3Int.h" | 36 #include "fts3Int.h" |
30 | 37 |
31 #define NM_MAX_TOKEN 12 | 38 #define NM_MAX_TOKEN 12 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 nOcc++; | 143 nOcc++; |
137 } | 144 } |
138 } | 145 } |
139 | 146 |
140 return nOcc; | 147 return nOcc; |
141 } | 148 } |
142 | 149 |
143 /* | 150 /* |
144 ** Tclcmd: fts3_near_match DOCUMENT EXPR ?OPTIONS? | 151 ** Tclcmd: fts3_near_match DOCUMENT EXPR ?OPTIONS? |
145 */ | 152 */ |
146 static int fts3_near_match_cmd( | 153 static int SQLITE_TCLAPI fts3_near_match_cmd( |
147 ClientData clientData, | 154 ClientData clientData, |
148 Tcl_Interp *interp, | 155 Tcl_Interp *interp, |
149 int objc, | 156 int objc, |
150 Tcl_Obj *CONST objv[] | 157 Tcl_Obj *CONST objv[] |
151 ){ | 158 ){ |
152 int nTotal = 0; | 159 int nTotal = 0; |
153 int rc; | 160 int rc; |
154 int ii; | 161 int ii; |
155 int nPhrase; | 162 int nPhrase; |
156 NearPhrase *aPhrase = 0; | 163 NearPhrase *aPhrase = 0; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 ** tests. For example: | 278 ** tests. For example: |
272 ** | 279 ** |
273 ** # Override incr-load settings for testing: | 280 ** # Override incr-load settings for testing: |
274 ** set cfg [fts3_configure_incr_load $new_chunksize $new_threshold] | 281 ** set cfg [fts3_configure_incr_load $new_chunksize $new_threshold] |
275 ** | 282 ** |
276 ** .... run tests .... | 283 ** .... run tests .... |
277 ** | 284 ** |
278 ** # Restore initial incr-load settings: | 285 ** # Restore initial incr-load settings: |
279 ** eval fts3_configure_incr_load $cfg | 286 ** eval fts3_configure_incr_load $cfg |
280 */ | 287 */ |
281 static int fts3_configure_incr_load_cmd( | 288 static int SQLITE_TCLAPI fts3_configure_incr_load_cmd( |
282 ClientData clientData, | 289 ClientData clientData, |
283 Tcl_Interp *interp, | 290 Tcl_Interp *interp, |
284 int objc, | 291 int objc, |
285 Tcl_Obj *CONST objv[] | 292 Tcl_Obj *CONST objv[] |
286 ){ | 293 ){ |
287 #ifdef SQLITE_ENABLE_FTS3 | 294 #ifdef SQLITE_ENABLE_FTS3 |
288 extern int test_fts3_node_chunksize; | 295 extern int test_fts3_node_chunksize; |
289 extern int test_fts3_node_chunk_threshold; | 296 extern int test_fts3_node_chunk_threshold; |
290 Tcl_Obj *pRet; | 297 Tcl_Obj *pRet; |
291 | 298 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 pCsr->aBuffer = sqlite3_malloc(nToken); | 458 pCsr->aBuffer = sqlite3_malloc(nToken); |
452 } | 459 } |
453 if( pCsr->aBuffer==0 ){ | 460 if( pCsr->aBuffer==0 ){ |
454 rc = SQLITE_NOMEM; | 461 rc = SQLITE_NOMEM; |
455 }else{ | 462 }else{ |
456 int i; | 463 int i; |
457 | 464 |
458 if( pCsr->iLangid & 0x00000001 ){ | 465 if( pCsr->iLangid & 0x00000001 ){ |
459 for(i=0; i<nToken; i++) pCsr->aBuffer[i] = pToken[i]; | 466 for(i=0; i<nToken; i++) pCsr->aBuffer[i] = pToken[i]; |
460 }else{ | 467 }else{ |
461 for(i=0; i<nToken; i++) pCsr->aBuffer[i] = testTolower(pToken[i]); | 468 for(i=0; i<nToken; i++) pCsr->aBuffer[i] = (char)testTolower(pToken[i]); |
462 } | 469 } |
463 pCsr->iToken++; | 470 pCsr->iToken++; |
464 pCsr->iInput = (int)(p - pCsr->aInput); | 471 pCsr->iInput = (int)(p - pCsr->aInput); |
465 | 472 |
466 *ppToken = pCsr->aBuffer; | 473 *ppToken = pCsr->aBuffer; |
467 *pnBytes = nToken; | 474 *pnBytes = nToken; |
468 *piStartOffset = (int)(pToken - pCsr->aInput); | 475 *piStartOffset = (int)(pToken - pCsr->aInput); |
469 *piEndOffset = (int)(p - pCsr->aInput); | 476 *piEndOffset = (int)(p - pCsr->aInput); |
470 *piPosition = pCsr->iToken; | 477 *piPosition = pCsr->iToken; |
471 } | 478 } |
472 } | 479 } |
473 | 480 |
474 return rc; | 481 return rc; |
475 } | 482 } |
476 | 483 |
477 static int testTokenizerLanguage( | 484 static int testTokenizerLanguage( |
478 sqlite3_tokenizer_cursor *pCursor, | 485 sqlite3_tokenizer_cursor *pCursor, |
479 int iLangid | 486 int iLangid |
480 ){ | 487 ){ |
481 int rc = SQLITE_OK; | 488 int rc = SQLITE_OK; |
482 test_tokenizer_cursor *pCsr = (test_tokenizer_cursor *)pCursor; | 489 test_tokenizer_cursor *pCsr = (test_tokenizer_cursor *)pCursor; |
483 pCsr->iLangid = iLangid; | 490 pCsr->iLangid = iLangid; |
484 if( pCsr->iLangid>=100 ){ | 491 if( pCsr->iLangid>=100 ){ |
485 rc = SQLITE_ERROR; | 492 rc = SQLITE_ERROR; |
486 } | 493 } |
487 return rc; | 494 return rc; |
488 } | 495 } |
489 #endif | 496 #endif |
490 | 497 |
491 static int fts3_test_tokenizer_cmd( | 498 static int SQLITE_TCLAPI fts3_test_tokenizer_cmd( |
492 ClientData clientData, | 499 ClientData clientData, |
493 Tcl_Interp *interp, | 500 Tcl_Interp *interp, |
494 int objc, | 501 int objc, |
495 Tcl_Obj *CONST objv[] | 502 Tcl_Obj *CONST objv[] |
496 ){ | 503 ){ |
497 #ifdef SQLITE_ENABLE_FTS3 | 504 #ifdef SQLITE_ENABLE_FTS3 |
498 static const sqlite3_tokenizer_module testTokenizerModule = { | 505 static const sqlite3_tokenizer_module testTokenizerModule = { |
499 1, | 506 1, |
500 testTokenizerCreate, | 507 testTokenizerCreate, |
501 testTokenizerDestroy, | 508 testTokenizerDestroy, |
502 testTokenizerOpen, | 509 testTokenizerOpen, |
503 testTokenizerClose, | 510 testTokenizerClose, |
504 testTokenizerNext, | 511 testTokenizerNext, |
505 testTokenizerLanguage | 512 testTokenizerLanguage |
506 }; | 513 }; |
507 const sqlite3_tokenizer_module *pPtr = &testTokenizerModule; | 514 const sqlite3_tokenizer_module *pPtr = &testTokenizerModule; |
508 if( objc!=1 ){ | 515 if( objc!=1 ){ |
509 Tcl_WrongNumArgs(interp, 1, objv, ""); | 516 Tcl_WrongNumArgs(interp, 1, objv, ""); |
510 return TCL_ERROR; | 517 return TCL_ERROR; |
511 } | 518 } |
512 Tcl_SetObjResult(interp, Tcl_NewByteArrayObj( | 519 Tcl_SetObjResult(interp, Tcl_NewByteArrayObj( |
513 (const unsigned char *)&pPtr, sizeof(sqlite3_tokenizer_module *) | 520 (const unsigned char *)&pPtr, sizeof(sqlite3_tokenizer_module *) |
514 )); | 521 )); |
515 #endif | 522 #endif |
516 UNUSED_PARAMETER(clientData); | 523 UNUSED_PARAMETER(clientData); |
517 return TCL_OK; | 524 return TCL_OK; |
518 } | 525 } |
519 | 526 |
520 static int fts3_test_varint_cmd( | 527 static int SQLITE_TCLAPI fts3_test_varint_cmd( |
521 ClientData clientData, | 528 ClientData clientData, |
522 Tcl_Interp *interp, | 529 Tcl_Interp *interp, |
523 int objc, | 530 int objc, |
524 Tcl_Obj *CONST objv[] | 531 Tcl_Obj *CONST objv[] |
525 ){ | 532 ){ |
526 #ifdef SQLITE_ENABLE_FTS3 | 533 #ifdef SQLITE_ENABLE_FTS3 |
527 char aBuf[24]; | 534 char aBuf[24]; |
528 int rc; | 535 int rc; |
529 Tcl_WideInt w, w2; | 536 Tcl_WideInt w; |
| 537 sqlite3_int64 w2; |
530 int nByte, nByte2; | 538 int nByte, nByte2; |
531 | 539 |
532 if( objc!=2 ){ | 540 if( objc!=2 ){ |
533 Tcl_WrongNumArgs(interp, 1, objv, "INTEGER"); | 541 Tcl_WrongNumArgs(interp, 1, objv, "INTEGER"); |
534 return TCL_ERROR; | 542 return TCL_ERROR; |
535 } | 543 } |
536 | 544 |
537 rc = Tcl_GetWideIntFromObj(interp, objv[1], &w); | 545 rc = Tcl_GetWideIntFromObj(interp, objv[1], &w); |
538 if( rc!=TCL_OK ) return rc; | 546 if( rc!=TCL_OK ) return rc; |
539 | 547 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 interp, "fts3_test_tokenizer", fts3_test_tokenizer_cmd, 0, 0 | 583 interp, "fts3_test_tokenizer", fts3_test_tokenizer_cmd, 0, 0 |
576 ); | 584 ); |
577 | 585 |
578 Tcl_CreateObjCommand( | 586 Tcl_CreateObjCommand( |
579 interp, "fts3_test_varint", fts3_test_varint_cmd, 0, 0 | 587 interp, "fts3_test_varint", fts3_test_varint_cmd, 0, 0 |
580 ); | 588 ); |
581 return TCL_OK; | 589 return TCL_OK; |
582 } | 590 } |
583 #endif /* SQLITE_ENABLE_FTS3 || SQLITE_ENABLE_FTS4 */ | 591 #endif /* SQLITE_ENABLE_FTS3 || SQLITE_ENABLE_FTS4 */ |
584 #endif /* ifdef SQLITE_TEST */ | 592 #endif /* ifdef SQLITE_TEST */ |
OLD | NEW |