Fossil

Check-in [73d27436]
Login

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

Overview
Comment:adding code, wiki, tickets, checkins search functionality
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | exp-search
Files: files | file ages | folders
SHA1:73d274360c6c9ddc62dbce2370b2a39dbc97a381
User & Date: Zach 2010-05-21 21:05:35
Context
2010-05-24
15:37
added a check for null document pointers in search_score that corrected search form crash check-in: cad393d5 user: Zeugmal tags: exp-search
2010-05-21
21:05
adding code, wiki, tickets, checkins search functionality check-in: 73d27436 user: Zach tags: exp-search
16:21
Fix issues with attachments on tickets. In the artifact viewer, do a better job of detecting JPEG images from the content prefix. check-in: 3343450e user: drh tags: trunk, release
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/db.c.

1059
1060
1061
1062
1063
1064
1065

































































1066
1067
1068
1069
1070
1071
1072
....
1176
1177
1178
1179
1180
1181
1182



1183
1184
1185
1186
1187
1188
1189
  int argc,
  sqlite3_value **argv
){
  if( g.zLogin!=0 ){
    sqlite3_result_text(context, g.zLogin, -1, SQLITE_STATIC);
  }
}


































































/*
** Implement the cgi() SQL function.  cgi() takes a an argument which is
** a name of CGI query parameter. The value of that parameter is returned, 
** if available. optional second argument will be returned if the first
** doesn't exist as a CGI parameter.
*/
................................................................................
*/
LOCAL void db_connection_init(void){
  sqlite3_exec(g.db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
  sqlite3_create_function(g.db, "user", 0, SQLITE_ANY, 0, db_sql_user, 0, 0);
  sqlite3_create_function(g.db, "cgi", 1, SQLITE_ANY, 0, db_sql_cgi, 0, 0);
  sqlite3_create_function(g.db, "cgi", 2, SQLITE_ANY, 0, db_sql_cgi, 0, 0);
  sqlite3_create_function(g.db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);



  sqlite3_create_function(
    g.db, "file_is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
  );
  if( g.fSqlTrace ){
    sqlite3_trace(g.db, db_sql_trace, 0);
  }
}







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







 







>
>
>







1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
....
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
  int argc,
  sqlite3_value **argv
){
  if( g.zLogin!=0 ){
    sqlite3_result_text(context, g.zLogin, -1, SQLITE_STATIC);
  }
}

/*
** Make the content_get function available within a SQL query.
*/
static void db_sql_content_get(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  int rid;
  Blob content;
  
  if( argc != 1 ) return;
  rid = sqlite3_value_int(argv[0]);
  content_get(rid, &content);
  sqlite3_result_text(context, blob_str(&content), -1, SQLITE_TRANSIENT);
}

/*
** Retrieve the most recent revision ID of a file.
*/
static void db_sql_get_file_rid(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  const unsigned char *fnid;
  int rid;
  Stmt q;
  
  if ( argc != 1 ) return;
  fnid = sqlite3_value_text(argv[0]);
  
  db_prepare(&q, "SELECT fid FROM mlink WHERE fnid=%Q and mid= "
                 "(SELECT objid FROM (SELECT objid, mtime FROM event WHERE objid IN "
                 "(SELECT mid FROM mlink WHERE fnid=%Q) "
                 "ORDER BY mtime DESC) LIMIT 1);", fnid, fnid);
  
  db_step(&q);
  rid = db_column_int(&q, 0);
  sqlite3_result_int(context, rid);
  db_finalize(&q);
}

/*
** Retrieve the most recent revision ID of a wiki entry.
*/
static void db_sql_get_wiki_rid(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  const unsigned char *tagid;
  int rid;
  Stmt q;
  
  if ( argc != 1 ) return;
  tagid = sqlite3_value_text(argv[0]);
  
  db_prepare(&q, "SELECT rid FROM tagxref WHERE tagid=%Q ORDER BY mtime DESC LIMIT 1", tagid);    
  db_step(&q);
  rid = db_column_int(&q, 0);
  sqlite3_result_int(context, rid);
  db_finalize(&q);
}

/*
** Implement the cgi() SQL function.  cgi() takes a an argument which is
** a name of CGI query parameter. The value of that parameter is returned, 
** if available. optional second argument will be returned if the first
** doesn't exist as a CGI parameter.
*/
................................................................................
*/
LOCAL void db_connection_init(void){
  sqlite3_exec(g.db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
  sqlite3_create_function(g.db, "user", 0, SQLITE_ANY, 0, db_sql_user, 0, 0);
  sqlite3_create_function(g.db, "cgi", 1, SQLITE_ANY, 0, db_sql_cgi, 0, 0);
  sqlite3_create_function(g.db, "cgi", 2, SQLITE_ANY, 0, db_sql_cgi, 0, 0);
  sqlite3_create_function(g.db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
  sqlite3_create_function(g.db, "content_get", 1, SQLITE_ANY, 0, db_sql_content_get, 0, 0);
  sqlite3_create_function(g.db, "get_file_rid", 1, SQLITE_ANY, 0, db_sql_get_file_rid, 0, 0);
  sqlite3_create_function(g.db, "get_wiki_rid", 1, SQLITE_ANY, 0, db_sql_get_wiki_rid, 0, 0);  
  sqlite3_create_function(
    g.db, "file_is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
  );
  if( g.fSqlTrace ){
    sqlite3_trace(g.db, db_sql_trace, 0);
  }
}

Changes to src/search.c.

160
161
162
163
164
165
166


































































































167
168
169
170
171
172
173
** using the given Search object.  Once this function is registered,
** do not delete the Search object.
*/
void search_sql_setup(Search *p){
  sqlite3_create_function(g.db, "score", 1, SQLITE_UTF8, p,
     search_score_sqlfunc, 0, 0);
}



































































































/*
** Testing the search function.
**
** COMMAND: search
** %fossil search pattern...
**







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







160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
** using the given Search object.  Once this function is registered,
** do not delete the Search object.
*/
void search_sql_setup(Search *p){
  sqlite3_create_function(g.db, "score", 1, SQLITE_UTF8, p,
     search_score_sqlfunc, 0, 0);
}

/*
** WEBPAGE: search
** URL: /search
*/
void search(void){
  const char *zType;
  const char *zSrchType;
  const char *zTitle;
  const char *zContent;
  const char *zSrch;
  const char *zUuid;
  const char *zRid;
  char zrn[4];
  char zshUuid[10];
  int zScore;
  int zSrchTypeFlag;
  
  Search *zSrchpat;
  Stmt q;

  zSrch = PD("search", "");
  zSrchType = PD("type", "");
  zSrchpat = search_init(zSrch);
  search_sql_setup(zSrchpat);

  login_check_credentials();
  
  if( !g.okHistory ){ login_needed(); return; }
  
  db_prepare(&q, "SELECT type, rid, title, content, score(content) AS score FROM "
                 "                                                                         "
                 "(SELECT 'checkin' AS type, objid AS rid, coalesce(ecomment, comment) AS title, "
                 "coalesce(ecomment, comment) AS content FROM event WHERE type='ci' UNION ALL "
                 "SELECT 'code' AS type, rid, title, content FROM "
                 "(SELECT title, rid, content_get(rid) as content FROM "
                 "(SELECT name AS title, get_file_rid(fnid) AS rid FROM "
                 "(SELECT name, fnid FROM filename))) UNION ALL "
                 "                                                                         "
                 "SELECT 'ticket' AS type, tkt_uuid AS rid, title, coalesce(title, comment) AS content FROM ticket UNION ALL "
                 "SELECT 'wiki' AS type, rid, SUBSTR(title, 6) AS title, content_get(rid) as content FROM "
                 "(SELECT tagname AS title, get_wiki_rid(tagid) AS rid FROM "
                 "(SELECT tagname, tagid FROM tag WHERE tagname LIKE 'wiki-%%')))"
                 "ORDER BY score DESC;");  
  
  zSrchTypeFlag = 0;
  if (strcmp(zSrchType, "code") == 0)
    zSrchTypeFlag = 1;
  else if (strcmp(zSrchType, "tickets") == 0)
    zSrchTypeFlag = 2;
  else if (strcmp(zSrchType, "checkins") == 0)
    zSrchTypeFlag = 3;
  else if (strcmp(zSrchType, "wiki") == 0)
    zSrchTypeFlag = 4;
  
  style_header("Search");
  style_submenu_element("Code", "Code", "search?search=%T&type=code", zSrch);
  style_submenu_element("Tickets", "Tickets", "search?search=%T&type=tickets", zSrch);
  style_submenu_element("Checkins", "Checkins", "search?search=%T&type=checkins", zSrch);
  style_submenu_element("Wiki", "Wiki", "search?search=%T&type=wiki", zSrch);
  @ <table border=1>
  @ <tr><td>link</td><td>relevance</td><td>title</td><td>type</td></tr>
  while (db_step(&q) == SQLITE_ROW){
    zType = db_column_text(&q, 0);
    zRid = db_column_text(&q, 1);
    zTitle = db_column_text(&q, 2);
    zContent = db_column_text(&q, 3); 
    zScore = db_column_int(&q, 4);
    
    sprintf(zrn, "%i", zScore);
    if (zScore > 0){
      if (strcmp(zType, "code") == 0 && (zSrchTypeFlag == 0 || zSrchTypeFlag == 1)){
        zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%h", zRid);
        strncpy(zshUuid, zUuid, 10);
        @ <tr><td><a href='/artifact?name=%h(zUuid)'>%h(zshUuid)</a></td><td>%h(zrn)</td>
        @ <td>%h(zTitle)</td><td>%h(zType)</td></tr>
      }
      else if (strcmp(zType, "ticket") == 0 && (zSrchTypeFlag == 0 || zSrchTypeFlag == 2)){
        strncpy(zshUuid, zRid, 10);
        @ <tr><td><a href='/tktview?name=%h(zRid)'>%h(zshUuid)</a></td><td>%h(zrn)</td>
        @ <td>%h(zTitle)</td><td>%h(zType)</td></tr>
      }
      else if (strcmp(zType, "checkin") == 0 && (zSrchTypeFlag == 0 || zSrchTypeFlag == 3)){
        zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%h", zRid);
        strncpy(zshUuid, zUuid, 10);
        @ <tr><td><a href='info/%h(zUuid)'>%h(zshUuid)</a></td><td>%h(zrn)</td>
        @ <td>%h(zTitle)</td><td>%h(zType)</td></tr>
      }
      else if (strcmp(zType, "wiki") == 0 && (zSrchTypeFlag == 0 || zSrchTypeFlag == 4)){
        @ <tr><td><a href='/wiki?name=%h(zTitle)'>%h(zTitle)</a></td><td>%h(zrn)</td>
        @ <td>%h(zTitle)</td><td>%h(zType)</td></tr>
      }
    }
  }
  @ </table>
  db_finalize(&q);
  style_footer();
}

/*
** Testing the search function.
**
** COMMAND: search
** %fossil search pattern...
**

Changes to src/style.c.

198
199
200
201
202
203
204










205
206
207
208
209
210
211
...
288
289
290
291
292
293
294






295
296
297
298
299
300
301
@      if {[info exists login]} {
@        puts "Logged in as $login"
@      } else {
@        puts "Not logged in"
@      }
@   </th1></nobr></div>
@ </div>










@ <div class="mainmenu"><th1>
@ html "<a href='$baseurl$index_page'>Home</a> "
@ if {[anycap jor]} {
@   html "<a href='$baseurl/timeline'>Timeline</a> "
@ }
@ if {[hascap oh]} {
@   html "<a href='$baseurl/dir?ci=tip'>Files</a> "
................................................................................
@ }
@
@ /* The header across the top of the page */
@ div.header {
@   display: table;
@   width: 100%;
@ }






@
@ /* The main menu bar that appears at the top of the page beneath
@ ** the header */
@ div.mainmenu {
@   padding: 5px 10px 5px 10px;
@   font-size: 0.9em;
@   font-weight: bold;







>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>







198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
...
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
@      if {[info exists login]} {
@        puts "Logged in as $login"
@      } else {
@        puts "Not logged in"
@      }
@   </th1></nobr></div>
@ </div>
@ <th1>
@ if {[hascap h]} {
@ html "<div class='fullsrch'>"
@ html " <form action='/search' method='post'>"
@ html " <input type='text' name='search' size=20/>"
@ html " <input type='submit' value='Search'/>"
@ html " </form>"
@ html "</div>"
@ }
@ </th1>
@ <div class="mainmenu"><th1>
@ html "<a href='$baseurl$index_page'>Home</a> "
@ if {[anycap jor]} {
@   html "<a href='$baseurl/timeline'>Timeline</a> "
@ }
@ if {[hascap oh]} {
@   html "<a href='$baseurl/dir?ci=tip'>Files</a> "
................................................................................
@ }
@
@ /* The header across the top of the page */
@ div.header {
@   display: table;
@   width: 100%;
@ }
@
@ /* The search bar displayed at the top of the page */
@ div.fullsrch {
@   float: right;
@   margin: 2px 5px 2px 0px;
@ }
@
@ /* The main menu bar that appears at the top of the page beneath
@ ** the header */
@ div.mainmenu {
@   padding: 5px 10px 5px 10px;
@   font-size: 0.9em;
@   font-weight: bold;