Changes On Branch exp-search
Not logged in

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

Changes In Branch exp-search Excluding Merge-Ins

This is equivalent to a diff from 3343450e64 to 0fd61810c4

2010-06-10
19:19
Change the title of the home page from "Fossil Home Page" to simply "Home Page". Leaf check-in: 0fd61810c4 user: drh tags: exp-search
18:50
Use the qoute() function to encode setting value for the "configure export" command. This allows the binary logo image to be exported. check-in: 59fcfb777d user: drh tags: exp-search
2010-05-22
11:28
Fix memory leaks associated with the cgi_rfc822_datestamp() function. check-in: 99dcff4d28 user: drh tags: trunk
2010-05-21
21:05
adding code, wiki, tickets, checkins search functionality check-in: 73d274360c 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: 3343450e64 user: drh tags: trunk, release
15:16
Fix an unterminated string in the information viewer for attachments. check-in: 65d2067247 user: drh tags: trunk

Changes to src/configure.c.

346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
    db_text(0, "SELECT datetime('now')")
  );
  for(i=0; i<count(aConfig); i++){
    if( (aConfig[i].groupMask & mask)!=0 ){
      const char *zName = aConfig[i].zName;
      if( zName[0]!='@' ){
        char *zValue = db_text(0, 
            "SELECT value FROM config WHERE name=%Q", zName);
        if( zValue ){
          blob_appendf(&out,"REPLACE INTO config VALUES(%Q,%Q);\n", 
                       zName, zValue);
        }
        free(zValue);
      }else{
        configure_render_special_name(zName, &out);
      }
    }







|

|







346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
    db_text(0, "SELECT datetime('now')")
  );
  for(i=0; i<count(aConfig); i++){
    if( (aConfig[i].groupMask & mask)!=0 ){
      const char *zName = aConfig[i].zName;
      if( zName[0]!='@' ){
        char *zValue = db_text(0, 
            "SELECT quote(value) FROM config WHERE name=%Q", zName);
        if( zValue ){
          blob_appendf(&out,"REPLACE INTO config VALUES(%Q,%s);\n", 
                       zName, zValue);
        }
        free(zValue);
      }else{
        configure_render_special_name(zName, &out);
      }
    }

Changes to src/db.c.

1059
1060
1061
1062
1063
1064
1065

































































1066
1067
1068
1069
1070
1071
1072
  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.
*/







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







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
  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.
*/
1176
1177
1178
1179
1180
1181
1182



1183
1184
1185
1186
1187
1188
1189
*/
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);
  }
}







>
>
>







1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
*/
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.

104
105
106
107
108
109
110

111
112
113
114
115
116
117
int search_score(Search *p, const char *zDoc){
  int iPrev = 999;
  int score = 10;
  int iBonus = 0;
  int i, j;
  unsigned char seen[8];


  memset(seen, 0, sizeof(seen));
  for(i=0; zDoc[i]; i++){
    char c = zDoc[i];
    if( isBoundary[c&0xff] ) continue;
    for(j=0; j<p->nTerm; j++){
      int n = p->a[j].n;
      if( sqlite3_strnicmp(p->a[j].z, &zDoc[i], n)==0 ){







>







104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
int search_score(Search *p, const char *zDoc){
  int iPrev = 999;
  int score = 10;
  int iBonus = 0;
  int i, j;
  unsigned char seen[8];

  if (zDoc == 0) return 0; 
  memset(seen, 0, sizeof(seen));
  for(i=0; zDoc[i]; i++){
    char c = zDoc[i];
    if( isBoundary[c&0xff] ) continue;
    for(j=0; j<p->nTerm; j++){
      int n = p->a[j].n;
      if( sqlite3_strnicmp(p->a[j].z, &zDoc[i], n)==0 ){
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...
**







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







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
272
** 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
@      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> "







>
>
>
>
>
>
>
>
>
>







198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
@      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> "
288
289
290
291
292
293
294






295
296
297
298
299
300
301
@ }
@
@ /* 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;







>
>
>
>
>
>







298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
@ }
@
@ /* 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;

Changes to www/index.wiki.

1
2
3
4
5
6
7
8
<title>Fossil Home Page</title>


<p align="center">
<font size="5">
<b>Fossil:</b>
<i>Simple, high-reliability, distributed software configuration management</i>
</font>
|







1
2
3
4
5
6
7
8
<title>Home Page</title>


<p align="center">
<font size="5">
<b>Fossil:</b>
<i>Simple, high-reliability, distributed software configuration management</i>
</font>