Fossil SCM

Allow searching for wiki page titles as discussed in [forum:31d8831c2d9809fa].

preben 2023-09-26 10:18 trunk
Commit e6b8cc9f71f8991bf7cb58f7281943fa8ae3895281829950be97dec51f7d3297
1 file changed +20 -11
+20 -11
--- src/search.c
+++ src/search.c
@@ -1229,47 +1229,56 @@
12291229
12301230
/*
12311231
** This is a helper function for search_stext(). Writing into pOut
12321232
** the search text obtained from pIn according to zMimetype.
12331233
**
1234
+** If a title is not specified in zTitle (e.g. for wiki pages that do not
1235
+** include the title in the body), it is determined from the page content.
1236
+**
12341237
** The title of the document is the first line of text. All subsequent
12351238
** lines are the body. If the document has no title, the first line
12361239
** is blank.
12371240
*/
12381241
static void get_stext_by_mimetype(
12391242
Blob *pIn,
12401243
const char *zMimetype,
1244
+ const char *zTitle,
12411245
Blob *pOut
12421246
){
12431247
Blob html, title;
12441248
blob_init(&html, 0, 0);
1245
- blob_init(&title, 0, 0);
1249
+ if( zTitle==0 ){
1250
+ blob_init(&title, 0, 0);
1251
+ }else{
1252
+ blob_init(&title, zTitle, -1);
1253
+ }
12461254
if( zMimetype==0 ) zMimetype = "text/plain";
12471255
if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")==0 ){
12481256
Blob tail;
12491257
blob_init(&tail, 0, 0);
1250
- if( wiki_find_title(pIn, &title, &tail) ){
1258
+ if( blob_size(&title) ){
1259
+ wiki_convert(pIn, &html, 0);
1260
+ }else if( wiki_find_title(pIn, &title, &tail) ){
12511261
blob_appendf(pOut, "%s\n", blob_str(&title));
12521262
wiki_convert(&tail, &html, 0);
12531263
blob_reset(&tail);
12541264
}else{
12551265
blob_append(pOut, "\n", 1);
12561266
wiki_convert(pIn, &html, 0);
12571267
}
12581268
html_to_plaintext(blob_str(&html), pOut);
12591269
}else if( fossil_strcmp(zMimetype,"text/x-markdown")==0 ){
1260
- markdown_to_html(pIn, &title, &html);
1270
+ markdown_to_html(pIn, blob_size(&title) ? NULL : &title, &html);
12611271
if( blob_size(&title) ){
12621272
blob_appendf(pOut, "%s\n", blob_str(&title));
12631273
}else{
12641274
blob_append(pOut, "\n", 1);
12651275
}
12661276
html_to_plaintext(blob_str(&html), pOut);
12671277
}else if( fossil_strcmp(zMimetype,"text/html")==0 ){
1268
- if( doc_is_embedded_html(pIn, &title) ){
1269
- blob_appendf(pOut, "%s\n", blob_str(&title));
1270
- }
1278
+ if( blob_size(&title)==0 ) doc_is_embedded_html(pIn, &title);
1279
+ blob_appendf(pOut, "%s\n", blob_str(&title));
12711280
html_to_plaintext(blob_str(pIn), pOut);
12721281
}else{
12731282
blob_append(pOut, "\n", 1);
12741283
blob_append(pOut, blob_buffer(pIn), blob_size(pIn));
12751284
}
@@ -1305,11 +1314,11 @@
13051314
blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i));
13061315
}else{
13071316
Blob txt;
13081317
blob_init(&txt, db_column_text(pQuery,i), -1);
13091318
blob_appendf(pAccum, "%s: ", zColName);
1310
- get_stext_by_mimetype(&txt, zMime, pAccum);
1319
+ get_stext_by_mimetype(&txt, zMime, NULL, pAccum);
13111320
blob_append(pAccum, " |", 2);
13121321
blob_reset(&txt);
13131322
}
13141323
}
13151324
}
@@ -1344,11 +1353,11 @@
13441353
switch( cType ){
13451354
case 'd': { /* Documents */
13461355
Blob doc;
13471356
content_get(rid, &doc);
13481357
blob_to_utf8_no_bom(&doc, 0);
1349
- get_stext_by_mimetype(&doc, mimetype_from_name(zName), pOut);
1358
+ get_stext_by_mimetype(&doc, mimetype_from_name(zName), NULL, pOut);
13501359
blob_reset(&doc);
13511360
break;
13521361
}
13531362
case 'f': /* Forum messages */
13541363
case 'e': /* Tech Notes */
@@ -1366,11 +1375,11 @@
13661375
blob_appendf(&wiki, "From %s:\n\n%s", pWiki->zUser, pWiki->zWiki);
13671376
}else{
13681377
blob_init(&wiki, pWiki->zWiki, -1);
13691378
}
13701379
get_stext_by_mimetype(&wiki, wiki_filter_mimetypes(pWiki->zMimetype),
1371
- pOut);
1380
+ cType=='w' ? pWiki->zWikiTitle : NULL, pOut);
13721381
blob_reset(&wiki);
13731382
manifest_destroy(pWiki);
13741383
break;
13751384
}
13761385
case 'c': { /* Check-in Comments */
@@ -1396,11 +1405,11 @@
13961405
db_column_blob(&q, 0, pOut);
13971406
}else{
13981407
Blob x;
13991408
blob_init(&x,0,0);
14001409
db_column_blob(&q, 0, &x);
1401
- get_stext_by_mimetype(&x, "text/x-fossil-wiki", pOut);
1410
+ get_stext_by_mimetype(&x, "text/x-fossil-wiki", NULL, pOut);
14021411
blob_reset(&x);
14031412
}
14041413
}
14051414
db_reset(&q);
14061415
break;
@@ -1507,11 +1516,11 @@
15071516
Blob in, out;
15081517
db_find_and_open_repository(0,0);
15091518
if( g.argc!=4 ) usage("FILENAME MIMETYPE");
15101519
blob_read_from_file(&in, g.argv[2], ExtFILE);
15111520
blob_init(&out, 0, 0);
1512
- get_stext_by_mimetype(&in, g.argv[3], &out);
1521
+ get_stext_by_mimetype(&in, g.argv[3], NULL, &out);
15131522
fossil_print("%s\n",blob_str(&out));
15141523
blob_reset(&in);
15151524
blob_reset(&out);
15161525
}
15171526
15181527
--- src/search.c
+++ src/search.c
@@ -1229,47 +1229,56 @@
1229
1230 /*
1231 ** This is a helper function for search_stext(). Writing into pOut
1232 ** the search text obtained from pIn according to zMimetype.
1233 **
 
 
 
1234 ** The title of the document is the first line of text. All subsequent
1235 ** lines are the body. If the document has no title, the first line
1236 ** is blank.
1237 */
1238 static void get_stext_by_mimetype(
1239 Blob *pIn,
1240 const char *zMimetype,
 
1241 Blob *pOut
1242 ){
1243 Blob html, title;
1244 blob_init(&html, 0, 0);
1245 blob_init(&title, 0, 0);
 
 
 
 
1246 if( zMimetype==0 ) zMimetype = "text/plain";
1247 if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")==0 ){
1248 Blob tail;
1249 blob_init(&tail, 0, 0);
1250 if( wiki_find_title(pIn, &title, &tail) ){
 
 
1251 blob_appendf(pOut, "%s\n", blob_str(&title));
1252 wiki_convert(&tail, &html, 0);
1253 blob_reset(&tail);
1254 }else{
1255 blob_append(pOut, "\n", 1);
1256 wiki_convert(pIn, &html, 0);
1257 }
1258 html_to_plaintext(blob_str(&html), pOut);
1259 }else if( fossil_strcmp(zMimetype,"text/x-markdown")==0 ){
1260 markdown_to_html(pIn, &title, &html);
1261 if( blob_size(&title) ){
1262 blob_appendf(pOut, "%s\n", blob_str(&title));
1263 }else{
1264 blob_append(pOut, "\n", 1);
1265 }
1266 html_to_plaintext(blob_str(&html), pOut);
1267 }else if( fossil_strcmp(zMimetype,"text/html")==0 ){
1268 if( doc_is_embedded_html(pIn, &title) ){
1269 blob_appendf(pOut, "%s\n", blob_str(&title));
1270 }
1271 html_to_plaintext(blob_str(pIn), pOut);
1272 }else{
1273 blob_append(pOut, "\n", 1);
1274 blob_append(pOut, blob_buffer(pIn), blob_size(pIn));
1275 }
@@ -1305,11 +1314,11 @@
1305 blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i));
1306 }else{
1307 Blob txt;
1308 blob_init(&txt, db_column_text(pQuery,i), -1);
1309 blob_appendf(pAccum, "%s: ", zColName);
1310 get_stext_by_mimetype(&txt, zMime, pAccum);
1311 blob_append(pAccum, " |", 2);
1312 blob_reset(&txt);
1313 }
1314 }
1315 }
@@ -1344,11 +1353,11 @@
1344 switch( cType ){
1345 case 'd': { /* Documents */
1346 Blob doc;
1347 content_get(rid, &doc);
1348 blob_to_utf8_no_bom(&doc, 0);
1349 get_stext_by_mimetype(&doc, mimetype_from_name(zName), pOut);
1350 blob_reset(&doc);
1351 break;
1352 }
1353 case 'f': /* Forum messages */
1354 case 'e': /* Tech Notes */
@@ -1366,11 +1375,11 @@
1366 blob_appendf(&wiki, "From %s:\n\n%s", pWiki->zUser, pWiki->zWiki);
1367 }else{
1368 blob_init(&wiki, pWiki->zWiki, -1);
1369 }
1370 get_stext_by_mimetype(&wiki, wiki_filter_mimetypes(pWiki->zMimetype),
1371 pOut);
1372 blob_reset(&wiki);
1373 manifest_destroy(pWiki);
1374 break;
1375 }
1376 case 'c': { /* Check-in Comments */
@@ -1396,11 +1405,11 @@
1396 db_column_blob(&q, 0, pOut);
1397 }else{
1398 Blob x;
1399 blob_init(&x,0,0);
1400 db_column_blob(&q, 0, &x);
1401 get_stext_by_mimetype(&x, "text/x-fossil-wiki", pOut);
1402 blob_reset(&x);
1403 }
1404 }
1405 db_reset(&q);
1406 break;
@@ -1507,11 +1516,11 @@
1507 Blob in, out;
1508 db_find_and_open_repository(0,0);
1509 if( g.argc!=4 ) usage("FILENAME MIMETYPE");
1510 blob_read_from_file(&in, g.argv[2], ExtFILE);
1511 blob_init(&out, 0, 0);
1512 get_stext_by_mimetype(&in, g.argv[3], &out);
1513 fossil_print("%s\n",blob_str(&out));
1514 blob_reset(&in);
1515 blob_reset(&out);
1516 }
1517
1518
--- src/search.c
+++ src/search.c
@@ -1229,47 +1229,56 @@
1229
1230 /*
1231 ** This is a helper function for search_stext(). Writing into pOut
1232 ** the search text obtained from pIn according to zMimetype.
1233 **
1234 ** If a title is not specified in zTitle (e.g. for wiki pages that do not
1235 ** include the title in the body), it is determined from the page content.
1236 **
1237 ** The title of the document is the first line of text. All subsequent
1238 ** lines are the body. If the document has no title, the first line
1239 ** is blank.
1240 */
1241 static void get_stext_by_mimetype(
1242 Blob *pIn,
1243 const char *zMimetype,
1244 const char *zTitle,
1245 Blob *pOut
1246 ){
1247 Blob html, title;
1248 blob_init(&html, 0, 0);
1249 if( zTitle==0 ){
1250 blob_init(&title, 0, 0);
1251 }else{
1252 blob_init(&title, zTitle, -1);
1253 }
1254 if( zMimetype==0 ) zMimetype = "text/plain";
1255 if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")==0 ){
1256 Blob tail;
1257 blob_init(&tail, 0, 0);
1258 if( blob_size(&title) ){
1259 wiki_convert(pIn, &html, 0);
1260 }else if( wiki_find_title(pIn, &title, &tail) ){
1261 blob_appendf(pOut, "%s\n", blob_str(&title));
1262 wiki_convert(&tail, &html, 0);
1263 blob_reset(&tail);
1264 }else{
1265 blob_append(pOut, "\n", 1);
1266 wiki_convert(pIn, &html, 0);
1267 }
1268 html_to_plaintext(blob_str(&html), pOut);
1269 }else if( fossil_strcmp(zMimetype,"text/x-markdown")==0 ){
1270 markdown_to_html(pIn, blob_size(&title) ? NULL : &title, &html);
1271 if( blob_size(&title) ){
1272 blob_appendf(pOut, "%s\n", blob_str(&title));
1273 }else{
1274 blob_append(pOut, "\n", 1);
1275 }
1276 html_to_plaintext(blob_str(&html), pOut);
1277 }else if( fossil_strcmp(zMimetype,"text/html")==0 ){
1278 if( blob_size(&title)==0 ) doc_is_embedded_html(pIn, &title);
1279 blob_appendf(pOut, "%s\n", blob_str(&title));
 
1280 html_to_plaintext(blob_str(pIn), pOut);
1281 }else{
1282 blob_append(pOut, "\n", 1);
1283 blob_append(pOut, blob_buffer(pIn), blob_size(pIn));
1284 }
@@ -1305,11 +1314,11 @@
1314 blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i));
1315 }else{
1316 Blob txt;
1317 blob_init(&txt, db_column_text(pQuery,i), -1);
1318 blob_appendf(pAccum, "%s: ", zColName);
1319 get_stext_by_mimetype(&txt, zMime, NULL, pAccum);
1320 blob_append(pAccum, " |", 2);
1321 blob_reset(&txt);
1322 }
1323 }
1324 }
@@ -1344,11 +1353,11 @@
1353 switch( cType ){
1354 case 'd': { /* Documents */
1355 Blob doc;
1356 content_get(rid, &doc);
1357 blob_to_utf8_no_bom(&doc, 0);
1358 get_stext_by_mimetype(&doc, mimetype_from_name(zName), NULL, pOut);
1359 blob_reset(&doc);
1360 break;
1361 }
1362 case 'f': /* Forum messages */
1363 case 'e': /* Tech Notes */
@@ -1366,11 +1375,11 @@
1375 blob_appendf(&wiki, "From %s:\n\n%s", pWiki->zUser, pWiki->zWiki);
1376 }else{
1377 blob_init(&wiki, pWiki->zWiki, -1);
1378 }
1379 get_stext_by_mimetype(&wiki, wiki_filter_mimetypes(pWiki->zMimetype),
1380 cType=='w' ? pWiki->zWikiTitle : NULL, pOut);
1381 blob_reset(&wiki);
1382 manifest_destroy(pWiki);
1383 break;
1384 }
1385 case 'c': { /* Check-in Comments */
@@ -1396,11 +1405,11 @@
1405 db_column_blob(&q, 0, pOut);
1406 }else{
1407 Blob x;
1408 blob_init(&x,0,0);
1409 db_column_blob(&q, 0, &x);
1410 get_stext_by_mimetype(&x, "text/x-fossil-wiki", NULL, pOut);
1411 blob_reset(&x);
1412 }
1413 }
1414 db_reset(&q);
1415 break;
@@ -1507,11 +1516,11 @@
1516 Blob in, out;
1517 db_find_and_open_repository(0,0);
1518 if( g.argc!=4 ) usage("FILENAME MIMETYPE");
1519 blob_read_from_file(&in, g.argv[2], ExtFILE);
1520 blob_init(&out, 0, 0);
1521 get_stext_by_mimetype(&in, g.argv[3], NULL, &out);
1522 fossil_print("%s\n",blob_str(&out));
1523 blob_reset(&in);
1524 blob_reset(&out);
1525 }
1526
1527

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button