Fossil SCM
Allow searching for wiki page titles as discussed in [forum:31d8831c2d9809fa].
Commit
e6b8cc9f71f8991bf7cb58f7281943fa8ae3895281829950be97dec51f7d3297
Parent
9b10bf45755514b…
1 file changed
+20
-11
+20
-11
| --- src/search.c | ||
| +++ src/search.c | ||
| @@ -1229,47 +1229,56 @@ | ||
| 1229 | 1229 | |
| 1230 | 1230 | /* |
| 1231 | 1231 | ** This is a helper function for search_stext(). Writing into pOut |
| 1232 | 1232 | ** the search text obtained from pIn according to zMimetype. |
| 1233 | 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 | +** | |
| 1234 | 1237 | ** The title of the document is the first line of text. All subsequent |
| 1235 | 1238 | ** lines are the body. If the document has no title, the first line |
| 1236 | 1239 | ** is blank. |
| 1237 | 1240 | */ |
| 1238 | 1241 | static void get_stext_by_mimetype( |
| 1239 | 1242 | Blob *pIn, |
| 1240 | 1243 | const char *zMimetype, |
| 1244 | + const char *zTitle, | |
| 1241 | 1245 | Blob *pOut |
| 1242 | 1246 | ){ |
| 1243 | 1247 | Blob html, title; |
| 1244 | 1248 | 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 | + } | |
| 1246 | 1254 | if( zMimetype==0 ) zMimetype = "text/plain"; |
| 1247 | 1255 | if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")==0 ){ |
| 1248 | 1256 | Blob tail; |
| 1249 | 1257 | 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) ){ | |
| 1251 | 1261 | blob_appendf(pOut, "%s\n", blob_str(&title)); |
| 1252 | 1262 | wiki_convert(&tail, &html, 0); |
| 1253 | 1263 | blob_reset(&tail); |
| 1254 | 1264 | }else{ |
| 1255 | 1265 | blob_append(pOut, "\n", 1); |
| 1256 | 1266 | wiki_convert(pIn, &html, 0); |
| 1257 | 1267 | } |
| 1258 | 1268 | html_to_plaintext(blob_str(&html), pOut); |
| 1259 | 1269 | }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); | |
| 1261 | 1271 | if( blob_size(&title) ){ |
| 1262 | 1272 | blob_appendf(pOut, "%s\n", blob_str(&title)); |
| 1263 | 1273 | }else{ |
| 1264 | 1274 | blob_append(pOut, "\n", 1); |
| 1265 | 1275 | } |
| 1266 | 1276 | html_to_plaintext(blob_str(&html), pOut); |
| 1267 | 1277 | }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)); | |
| 1271 | 1280 | html_to_plaintext(blob_str(pIn), pOut); |
| 1272 | 1281 | }else{ |
| 1273 | 1282 | blob_append(pOut, "\n", 1); |
| 1274 | 1283 | blob_append(pOut, blob_buffer(pIn), blob_size(pIn)); |
| 1275 | 1284 | } |
| @@ -1305,11 +1314,11 @@ | ||
| 1305 | 1314 | blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i)); |
| 1306 | 1315 | }else{ |
| 1307 | 1316 | Blob txt; |
| 1308 | 1317 | blob_init(&txt, db_column_text(pQuery,i), -1); |
| 1309 | 1318 | blob_appendf(pAccum, "%s: ", zColName); |
| 1310 | - get_stext_by_mimetype(&txt, zMime, pAccum); | |
| 1319 | + get_stext_by_mimetype(&txt, zMime, NULL, pAccum); | |
| 1311 | 1320 | blob_append(pAccum, " |", 2); |
| 1312 | 1321 | blob_reset(&txt); |
| 1313 | 1322 | } |
| 1314 | 1323 | } |
| 1315 | 1324 | } |
| @@ -1344,11 +1353,11 @@ | ||
| 1344 | 1353 | switch( cType ){ |
| 1345 | 1354 | case 'd': { /* Documents */ |
| 1346 | 1355 | Blob doc; |
| 1347 | 1356 | content_get(rid, &doc); |
| 1348 | 1357 | 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); | |
| 1350 | 1359 | blob_reset(&doc); |
| 1351 | 1360 | break; |
| 1352 | 1361 | } |
| 1353 | 1362 | case 'f': /* Forum messages */ |
| 1354 | 1363 | case 'e': /* Tech Notes */ |
| @@ -1366,11 +1375,11 @@ | ||
| 1366 | 1375 | blob_appendf(&wiki, "From %s:\n\n%s", pWiki->zUser, pWiki->zWiki); |
| 1367 | 1376 | }else{ |
| 1368 | 1377 | blob_init(&wiki, pWiki->zWiki, -1); |
| 1369 | 1378 | } |
| 1370 | 1379 | get_stext_by_mimetype(&wiki, wiki_filter_mimetypes(pWiki->zMimetype), |
| 1371 | - pOut); | |
| 1380 | + cType=='w' ? pWiki->zWikiTitle : NULL, pOut); | |
| 1372 | 1381 | blob_reset(&wiki); |
| 1373 | 1382 | manifest_destroy(pWiki); |
| 1374 | 1383 | break; |
| 1375 | 1384 | } |
| 1376 | 1385 | case 'c': { /* Check-in Comments */ |
| @@ -1396,11 +1405,11 @@ | ||
| 1396 | 1405 | db_column_blob(&q, 0, pOut); |
| 1397 | 1406 | }else{ |
| 1398 | 1407 | Blob x; |
| 1399 | 1408 | blob_init(&x,0,0); |
| 1400 | 1409 | 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); | |
| 1402 | 1411 | blob_reset(&x); |
| 1403 | 1412 | } |
| 1404 | 1413 | } |
| 1405 | 1414 | db_reset(&q); |
| 1406 | 1415 | break; |
| @@ -1507,11 +1516,11 @@ | ||
| 1507 | 1516 | Blob in, out; |
| 1508 | 1517 | db_find_and_open_repository(0,0); |
| 1509 | 1518 | if( g.argc!=4 ) usage("FILENAME MIMETYPE"); |
| 1510 | 1519 | blob_read_from_file(&in, g.argv[2], ExtFILE); |
| 1511 | 1520 | 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); | |
| 1513 | 1522 | fossil_print("%s\n",blob_str(&out)); |
| 1514 | 1523 | blob_reset(&in); |
| 1515 | 1524 | blob_reset(&out); |
| 1516 | 1525 | } |
| 1517 | 1526 | |
| 1518 | 1527 |
| --- 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 |