CVSTrac Legacy Code

Check-in [d339dba99a]
Login

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

Overview
Comment:(#822) add a secondary sort by date as default. Adding a "Sort by date"/"Sort by Relevance" toggle should be trivial from here.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:d339dba99aa7dc2881665eb29a2384313dd72adc
User & Date: cpb 2010-11-26 15:55:54
Context
2011-02-18
13:43
(#823) MAX() isn't a good function to use on numeric values stored as text. "Force" fields to numbers first. check-in: d199007454 user: cpb tags: trunk
2010-11-26
15:55
(#822) add a secondary sort by date as default. Adding a "Sort by date"/"Sort by Relevance" toggle should be trivial from here. check-in: d339dba99a user: cpb tags: trunk
2009-12-23
14:03
check for valid ticket and cn before trying to output anything check-in: 7b0e1f76c7 user: cpb tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to search.c.

366
367
368
369
370
371
372
373
374
375
376
377
378
379
380


381
382
383
384
385
386
387
388
389
390
391


392
393
394
395
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410
411
412
413
414
415


416
417
418
419
420
421
422
423
424
425


426
427
428
429
430

431
432
433
434
435
436
437
...
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
    }

    db = db_open();
    db_add_functions();
    sqlite3_create_function(db, "highlight", -1, SQLITE_ANY, 0,
                            highlightFunc, 0, 0);

    appendf(zSql,&i,sizeof(zSql),"SELECT type, score, obj, title, body FROM");
    if( srchTkt ){
      appendf(zSql,&i,sizeof(zSql), "%s SELECT "
         "1 AS type, "
         "search('%s',title,description,remarks) as score, "
         "tn AS obj, "
         "highlight('%s',title) as title, "
         "highlight('%s',description,remarks) as body FROM ticket "


         "WHERE score>0",
         zConnect, zPattern, zPattern, zPattern);
      zConnect = " UNION ALL";
    }
    if( srchCkin ){
      appendf(zSql,&i,sizeof(zSql),"%s SELECT "
         "2 AS type, "
         "search('%s',message) as score, "
         "cn AS obj, "
         "NULL as title, " /* ignored */
         "highlight('%s',message) as body FROM chng "


         "WHERE score>0",
         zConnect, zPattern, zPattern);
      zConnect = " UNION ALL";
    }
    if( srchWiki ){
      appendf(zSql,&i,sizeof(zSql),"%s SELECT "
         "3 AS type, "
         "search('%s',name, text) as score, "
         "name AS obj, "
         "highlight('%s',name) as title, "
         "highlight('%s',text) as body "

         "FROM (select name as nm, min(invtime) as tm FROM wiki GROUP BY name) "
         "    as x, wiki "
         "WHERE score>0 AND x.nm=wiki.name AND x.tm=wiki.invtime",
         zConnect, zPattern, zPattern, zPattern);
      zConnect = " UNION ALL";
    }
    if( srchFile ){
      appendf(zSql,&i,sizeof(zSql),"%s SELECT "
         "CASE WHEN isdir THEN 6 ELSE 4 END as type, "
         "search('%s', dir || '/' || base) as score, "
         "dir || '/' || base AS obj, "
         "dir || '/' || base as title, "
         "highlight('%s',dir || '/' || base) as body FROM file "


         "WHERE score>0",
         zConnect, zPattern, zPattern);
      zConnect = " UNION ALL";

      appendf(zSql,&i,sizeof(zSql),"%s SELECT "
         "5 AS type, "
         "search('%s', fname, description) as score, "
         "atn AS obj, "
         "fname as title, "
         "highlight('%s',fname, description) as body FROM attachment "


         "WHERE score>0 AND tn!=0",
         zConnect, zPattern, zPattern);
      zConnect = " UNION ALL";
    }
    appendf(zSql,&i,sizeof(zSql), ") ORDER BY score DESC LIMIT 30 OFFSET %d;",

            nPage*30);
    azResult = db_query("%s",zSql);
  }
  common_standard_menu("search", 0);
  common_add_help_item("CvstracSearch");
  common_header("Search");
  @ <form action="search" method="GET">
................................................................................
  }
  @ </p>
  @ </form>
  if( azResult && azResult[0] ){
    int i, n;
    @ <div>
    @ <hr>
    for(i=n=0; azResult[i]; i+=5, n++){
      @ <p>
      switch( atoi(azResult[i]) ){
        case 1: /* ticket */
          @ Ticket
          output_ticket(atoi(azResult[i+2]),0);
          @ : %s(azResult[i+3])
          break;







|






|
>
>










|
>
>










|
>












|
>
>









|
>
>




|
>







 







|







366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
...
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
    }

    db = db_open();
    db_add_functions();
    sqlite3_create_function(db, "highlight", -1, SQLITE_ANY, 0,
                            highlightFunc, 0, 0);

    appendf(zSql,&i,sizeof(zSql),"SELECT type, score, obj, title, body, date FROM");
    if( srchTkt ){
      appendf(zSql,&i,sizeof(zSql), "%s SELECT "
         "1 AS type, "
         "search('%s',title,description,remarks) as score, "
         "tn AS obj, "
         "highlight('%s',title) as title, "
         "highlight('%s',description,remarks) as body, "
         "changetime as date "
         "FROM ticket "
         "WHERE score>0",
         zConnect, zPattern, zPattern, zPattern);
      zConnect = " UNION ALL";
    }
    if( srchCkin ){
      appendf(zSql,&i,sizeof(zSql),"%s SELECT "
         "2 AS type, "
         "search('%s',message) as score, "
         "cn AS obj, "
         "NULL as title, " /* ignored */
         "highlight('%s',message) as body, "
         "date as date "
         "FROM chng "
         "WHERE score>0",
         zConnect, zPattern, zPattern);
      zConnect = " UNION ALL";
    }
    if( srchWiki ){
      appendf(zSql,&i,sizeof(zSql),"%s SELECT "
         "3 AS type, "
         "search('%s',name, text) as score, "
         "name AS obj, "
         "highlight('%s',name) as title, "
         "highlight('%s',text) as body, "
         "tm as date "
         "FROM (select name as nm, min(invtime) as tm FROM wiki GROUP BY name) "
         "    as x, wiki "
         "WHERE score>0 AND x.nm=wiki.name AND x.tm=wiki.invtime",
         zConnect, zPattern, zPattern, zPattern);
      zConnect = " UNION ALL";
    }
    if( srchFile ){
      appendf(zSql,&i,sizeof(zSql),"%s SELECT "
         "CASE WHEN isdir THEN 6 ELSE 4 END as type, "
         "search('%s', dir || '/' || base) as score, "
         "dir || '/' || base AS obj, "
         "dir || '/' || base as title, "
         "highlight('%s',dir || '/' || base) as body, "
         "0 AS date "
         "FROM file "
         "WHERE score>0",
         zConnect, zPattern, zPattern);
      zConnect = " UNION ALL";

      appendf(zSql,&i,sizeof(zSql),"%s SELECT "
         "5 AS type, "
         "search('%s', fname, description) as score, "
         "atn AS obj, "
         "fname as title, "
         "highlight('%s',fname, description) as body, "
         "date AS date "
         "FROM attachment "
         "WHERE score>0 AND tn!=0",
         zConnect, zPattern, zPattern);
      zConnect = " UNION ALL";
    }
    appendf(zSql,&i,sizeof(zSql), ") ORDER BY score DESC, date DESC "
            "LIMIT 30 OFFSET %d;",
            nPage*30);
    azResult = db_query("%s",zSql);
  }
  common_standard_menu("search", 0);
  common_add_help_item("CvstracSearch");
  common_header("Search");
  @ <form action="search" method="GET">
................................................................................
  }
  @ </p>
  @ </form>
  if( azResult && azResult[0] ){
    int i, n;
    @ <div>
    @ <hr>
    for(i=n=0; azResult[i]; i+=6, n++){
      @ <p>
      switch( atoi(azResult[i]) ){
        case 1: /* ticket */
          @ Ticket
          output_ticket(atoi(azResult[i+2]),0);
          @ : %s(azResult[i+3])
          break;