Fossil SCM
Remerge the Wiki title search enhancement, after fixing it so that it does not disrupt check-in comment search.
Commit
9d9bf1abfb59ec6536fe47a2beec7c6e8adb4ed7456eab8fe8203d9b3418405b
Parent
b7ef90c71679bfc…
1 file changed
+34
-26
+34
-26
| --- src/search.c | ||
| +++ src/search.c | ||
| @@ -1324,50 +1324,58 @@ | ||
| 1324 | 1324 | |
| 1325 | 1325 | /* |
| 1326 | 1326 | ** This is a helper function for search_stext(). Writing into pOut |
| 1327 | 1327 | ** the search text obtained from pIn according to zMimetype. |
| 1328 | 1328 | ** |
| 1329 | +** If a title is not specified in zTitle (e.g. for wiki pages that do not | |
| 1330 | +** include the title in the body), it is determined from the page content. | |
| 1331 | +** | |
| 1329 | 1332 | ** The title of the document is the first line of text. All subsequent |
| 1330 | 1333 | ** lines are the body. If the document has no title, the first line |
| 1331 | 1334 | ** is blank. |
| 1332 | 1335 | */ |
| 1333 | 1336 | static void get_stext_by_mimetype( |
| 1334 | 1337 | Blob *pIn, |
| 1335 | 1338 | const char *zMimetype, |
| 1339 | + const char *zTitle, | |
| 1336 | 1340 | Blob *pOut |
| 1337 | 1341 | ){ |
| 1338 | 1342 | Blob html, title; |
| 1343 | + Blob *pHtml = &html; | |
| 1339 | 1344 | blob_init(&html, 0, 0); |
| 1340 | - blob_init(&title, 0, 0); | |
| 1345 | + if( zTitle==0 ){ | |
| 1346 | + blob_init(&title, 0, 0); | |
| 1347 | + }else{ | |
| 1348 | + blob_init(&title, zTitle, -1); | |
| 1349 | + } | |
| 1341 | 1350 | if( zMimetype==0 ) zMimetype = "text/plain"; |
| 1342 | 1351 | if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")==0 ){ |
| 1343 | - Blob tail; | |
| 1344 | - blob_init(&tail, 0, 0); | |
| 1345 | - if( wiki_find_title(pIn, &title, &tail) ){ | |
| 1346 | - blob_appendf(pOut, "%s\n", blob_str(&title)); | |
| 1347 | - wiki_convert(&tail, &html, 0); | |
| 1348 | - blob_reset(&tail); | |
| 1349 | - }else{ | |
| 1350 | - blob_append(pOut, "\n", 1); | |
| 1352 | + if( blob_size(&title) ){ | |
| 1351 | 1353 | wiki_convert(pIn, &html, 0); |
| 1354 | + }else{ | |
| 1355 | + Blob tail; | |
| 1356 | + blob_init(&tail, 0, 0); | |
| 1357 | + if( wiki_find_title(pIn, &title, &tail) ){ | |
| 1358 | + blob_appendf(pOut, "%s\n", blob_str(&title)); | |
| 1359 | + wiki_convert(&tail, &html, 0); | |
| 1360 | + blob_reset(&tail); | |
| 1361 | + }else{ | |
| 1362 | + blob_append(pOut, "\n", 1); | |
| 1363 | + wiki_convert(pIn, &html, 0); | |
| 1364 | + } | |
| 1352 | 1365 | } |
| 1353 | 1366 | html_to_plaintext(blob_str(&html), pOut); |
| 1354 | 1367 | }else if( fossil_strcmp(zMimetype,"text/x-markdown")==0 ){ |
| 1355 | - markdown_to_html(pIn, &title, &html); | |
| 1356 | - if( blob_size(&title) ){ | |
| 1357 | - blob_appendf(pOut, "%s\n", blob_str(&title)); | |
| 1358 | - }else{ | |
| 1359 | - blob_append(pOut, "\n", 1); | |
| 1360 | - } | |
| 1361 | - html_to_plaintext(blob_str(&html), pOut); | |
| 1368 | + markdown_to_html(pIn, blob_size(&title) ? NULL : &title, &html); | |
| 1362 | 1369 | }else if( fossil_strcmp(zMimetype,"text/html")==0 ){ |
| 1363 | - if( doc_is_embedded_html(pIn, &title) ){ | |
| 1364 | - blob_appendf(pOut, "%s\n", blob_str(&title)); | |
| 1365 | - } | |
| 1366 | - html_to_plaintext(blob_str(pIn), pOut); | |
| 1370 | + if( blob_size(&title)==0 ) doc_is_embedded_html(pIn, &title); | |
| 1371 | + pHtml = pIn; | |
| 1372 | + } | |
| 1373 | + blob_appendf(pOut, "%s\n", blob_str(&title)); | |
| 1374 | + if( blob_size(pHtml) ){ | |
| 1375 | + html_to_plaintext(blob_str(pHtml), pOut); | |
| 1367 | 1376 | }else{ |
| 1368 | - blob_append(pOut, "\n", 1); | |
| 1369 | 1377 | blob_append(pOut, blob_buffer(pIn), blob_size(pIn)); |
| 1370 | 1378 | } |
| 1371 | 1379 | blob_reset(&html); |
| 1372 | 1380 | blob_reset(&title); |
| 1373 | 1381 | } |
| @@ -1400,11 +1408,11 @@ | ||
| 1400 | 1408 | blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i)); |
| 1401 | 1409 | }else{ |
| 1402 | 1410 | Blob txt; |
| 1403 | 1411 | blob_init(&txt, db_column_text(pQuery,i), -1); |
| 1404 | 1412 | blob_appendf(pAccum, "%s: ", zColName); |
| 1405 | - get_stext_by_mimetype(&txt, zMime, pAccum); | |
| 1413 | + get_stext_by_mimetype(&txt, zMime, NULL, pAccum); | |
| 1406 | 1414 | blob_append(pAccum, " |", 2); |
| 1407 | 1415 | blob_reset(&txt); |
| 1408 | 1416 | } |
| 1409 | 1417 | } |
| 1410 | 1418 | } |
| @@ -1439,11 +1447,11 @@ | ||
| 1439 | 1447 | switch( cType ){ |
| 1440 | 1448 | case 'd': { /* Documents */ |
| 1441 | 1449 | Blob doc; |
| 1442 | 1450 | content_get(rid, &doc); |
| 1443 | 1451 | blob_to_utf8_no_bom(&doc, 0); |
| 1444 | - get_stext_by_mimetype(&doc, mimetype_from_name(zName), pOut); | |
| 1452 | + get_stext_by_mimetype(&doc, mimetype_from_name(zName), NULL, pOut); | |
| 1445 | 1453 | blob_reset(&doc); |
| 1446 | 1454 | break; |
| 1447 | 1455 | } |
| 1448 | 1456 | case 'f': /* Forum messages */ |
| 1449 | 1457 | case 'e': /* Tech Notes */ |
| @@ -1461,11 +1469,11 @@ | ||
| 1461 | 1469 | blob_appendf(&wiki, "From %s:\n\n%s", pWiki->zUser, pWiki->zWiki); |
| 1462 | 1470 | }else{ |
| 1463 | 1471 | blob_init(&wiki, pWiki->zWiki, -1); |
| 1464 | 1472 | } |
| 1465 | 1473 | get_stext_by_mimetype(&wiki, wiki_filter_mimetypes(pWiki->zMimetype), |
| 1466 | - pOut); | |
| 1474 | + cType=='w' ? pWiki->zWikiTitle : NULL, pOut); | |
| 1467 | 1475 | blob_reset(&wiki); |
| 1468 | 1476 | manifest_destroy(pWiki); |
| 1469 | 1477 | break; |
| 1470 | 1478 | } |
| 1471 | 1479 | case 'c': { /* Check-in Comments */ |
| @@ -1491,11 +1499,11 @@ | ||
| 1491 | 1499 | db_column_blob(&q, 0, pOut); |
| 1492 | 1500 | }else{ |
| 1493 | 1501 | Blob x; |
| 1494 | 1502 | blob_init(&x,0,0); |
| 1495 | 1503 | db_column_blob(&q, 0, &x); |
| 1496 | - get_stext_by_mimetype(&x, "text/x-fossil-wiki", pOut); | |
| 1504 | + get_stext_by_mimetype(&x, "text/x-fossil-wiki", NULL, pOut); | |
| 1497 | 1505 | blob_reset(&x); |
| 1498 | 1506 | } |
| 1499 | 1507 | } |
| 1500 | 1508 | db_reset(&q); |
| 1501 | 1509 | break; |
| @@ -1602,11 +1610,11 @@ | ||
| 1602 | 1610 | Blob in, out; |
| 1603 | 1611 | db_find_and_open_repository(0,0); |
| 1604 | 1612 | if( g.argc!=4 ) usage("FILENAME MIMETYPE"); |
| 1605 | 1613 | blob_read_from_file(&in, g.argv[2], ExtFILE); |
| 1606 | 1614 | blob_init(&out, 0, 0); |
| 1607 | - get_stext_by_mimetype(&in, g.argv[3], &out); | |
| 1615 | + get_stext_by_mimetype(&in, g.argv[3], NULL, &out); | |
| 1608 | 1616 | fossil_print("%s\n",blob_str(&out)); |
| 1609 | 1617 | blob_reset(&in); |
| 1610 | 1618 | blob_reset(&out); |
| 1611 | 1619 | } |
| 1612 | 1620 | |
| 1613 | 1621 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -1324,50 +1324,58 @@ | |
| 1324 | |
| 1325 | /* |
| 1326 | ** This is a helper function for search_stext(). Writing into pOut |
| 1327 | ** the search text obtained from pIn according to zMimetype. |
| 1328 | ** |
| 1329 | ** The title of the document is the first line of text. All subsequent |
| 1330 | ** lines are the body. If the document has no title, the first line |
| 1331 | ** is blank. |
| 1332 | */ |
| 1333 | static void get_stext_by_mimetype( |
| 1334 | Blob *pIn, |
| 1335 | const char *zMimetype, |
| 1336 | Blob *pOut |
| 1337 | ){ |
| 1338 | Blob html, title; |
| 1339 | blob_init(&html, 0, 0); |
| 1340 | blob_init(&title, 0, 0); |
| 1341 | if( zMimetype==0 ) zMimetype = "text/plain"; |
| 1342 | if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")==0 ){ |
| 1343 | Blob tail; |
| 1344 | blob_init(&tail, 0, 0); |
| 1345 | if( wiki_find_title(pIn, &title, &tail) ){ |
| 1346 | blob_appendf(pOut, "%s\n", blob_str(&title)); |
| 1347 | wiki_convert(&tail, &html, 0); |
| 1348 | blob_reset(&tail); |
| 1349 | }else{ |
| 1350 | blob_append(pOut, "\n", 1); |
| 1351 | wiki_convert(pIn, &html, 0); |
| 1352 | } |
| 1353 | html_to_plaintext(blob_str(&html), pOut); |
| 1354 | }else if( fossil_strcmp(zMimetype,"text/x-markdown")==0 ){ |
| 1355 | markdown_to_html(pIn, &title, &html); |
| 1356 | if( blob_size(&title) ){ |
| 1357 | blob_appendf(pOut, "%s\n", blob_str(&title)); |
| 1358 | }else{ |
| 1359 | blob_append(pOut, "\n", 1); |
| 1360 | } |
| 1361 | html_to_plaintext(blob_str(&html), pOut); |
| 1362 | }else if( fossil_strcmp(zMimetype,"text/html")==0 ){ |
| 1363 | if( doc_is_embedded_html(pIn, &title) ){ |
| 1364 | blob_appendf(pOut, "%s\n", blob_str(&title)); |
| 1365 | } |
| 1366 | html_to_plaintext(blob_str(pIn), pOut); |
| 1367 | }else{ |
| 1368 | blob_append(pOut, "\n", 1); |
| 1369 | blob_append(pOut, blob_buffer(pIn), blob_size(pIn)); |
| 1370 | } |
| 1371 | blob_reset(&html); |
| 1372 | blob_reset(&title); |
| 1373 | } |
| @@ -1400,11 +1408,11 @@ | |
| 1400 | blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i)); |
| 1401 | }else{ |
| 1402 | Blob txt; |
| 1403 | blob_init(&txt, db_column_text(pQuery,i), -1); |
| 1404 | blob_appendf(pAccum, "%s: ", zColName); |
| 1405 | get_stext_by_mimetype(&txt, zMime, pAccum); |
| 1406 | blob_append(pAccum, " |", 2); |
| 1407 | blob_reset(&txt); |
| 1408 | } |
| 1409 | } |
| 1410 | } |
| @@ -1439,11 +1447,11 @@ | |
| 1439 | switch( cType ){ |
| 1440 | case 'd': { /* Documents */ |
| 1441 | Blob doc; |
| 1442 | content_get(rid, &doc); |
| 1443 | blob_to_utf8_no_bom(&doc, 0); |
| 1444 | get_stext_by_mimetype(&doc, mimetype_from_name(zName), pOut); |
| 1445 | blob_reset(&doc); |
| 1446 | break; |
| 1447 | } |
| 1448 | case 'f': /* Forum messages */ |
| 1449 | case 'e': /* Tech Notes */ |
| @@ -1461,11 +1469,11 @@ | |
| 1461 | blob_appendf(&wiki, "From %s:\n\n%s", pWiki->zUser, pWiki->zWiki); |
| 1462 | }else{ |
| 1463 | blob_init(&wiki, pWiki->zWiki, -1); |
| 1464 | } |
| 1465 | get_stext_by_mimetype(&wiki, wiki_filter_mimetypes(pWiki->zMimetype), |
| 1466 | pOut); |
| 1467 | blob_reset(&wiki); |
| 1468 | manifest_destroy(pWiki); |
| 1469 | break; |
| 1470 | } |
| 1471 | case 'c': { /* Check-in Comments */ |
| @@ -1491,11 +1499,11 @@ | |
| 1491 | db_column_blob(&q, 0, pOut); |
| 1492 | }else{ |
| 1493 | Blob x; |
| 1494 | blob_init(&x,0,0); |
| 1495 | db_column_blob(&q, 0, &x); |
| 1496 | get_stext_by_mimetype(&x, "text/x-fossil-wiki", pOut); |
| 1497 | blob_reset(&x); |
| 1498 | } |
| 1499 | } |
| 1500 | db_reset(&q); |
| 1501 | break; |
| @@ -1602,11 +1610,11 @@ | |
| 1602 | Blob in, out; |
| 1603 | db_find_and_open_repository(0,0); |
| 1604 | if( g.argc!=4 ) usage("FILENAME MIMETYPE"); |
| 1605 | blob_read_from_file(&in, g.argv[2], ExtFILE); |
| 1606 | blob_init(&out, 0, 0); |
| 1607 | get_stext_by_mimetype(&in, g.argv[3], &out); |
| 1608 | fossil_print("%s\n",blob_str(&out)); |
| 1609 | blob_reset(&in); |
| 1610 | blob_reset(&out); |
| 1611 | } |
| 1612 | |
| 1613 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -1324,50 +1324,58 @@ | |
| 1324 | |
| 1325 | /* |
| 1326 | ** This is a helper function for search_stext(). Writing into pOut |
| 1327 | ** the search text obtained from pIn according to zMimetype. |
| 1328 | ** |
| 1329 | ** If a title is not specified in zTitle (e.g. for wiki pages that do not |
| 1330 | ** include the title in the body), it is determined from the page content. |
| 1331 | ** |
| 1332 | ** The title of the document is the first line of text. All subsequent |
| 1333 | ** lines are the body. If the document has no title, the first line |
| 1334 | ** is blank. |
| 1335 | */ |
| 1336 | static void get_stext_by_mimetype( |
| 1337 | Blob *pIn, |
| 1338 | const char *zMimetype, |
| 1339 | const char *zTitle, |
| 1340 | Blob *pOut |
| 1341 | ){ |
| 1342 | Blob html, title; |
| 1343 | Blob *pHtml = &html; |
| 1344 | blob_init(&html, 0, 0); |
| 1345 | if( zTitle==0 ){ |
| 1346 | blob_init(&title, 0, 0); |
| 1347 | }else{ |
| 1348 | blob_init(&title, zTitle, -1); |
| 1349 | } |
| 1350 | if( zMimetype==0 ) zMimetype = "text/plain"; |
| 1351 | if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")==0 ){ |
| 1352 | if( blob_size(&title) ){ |
| 1353 | wiki_convert(pIn, &html, 0); |
| 1354 | }else{ |
| 1355 | Blob tail; |
| 1356 | blob_init(&tail, 0, 0); |
| 1357 | if( wiki_find_title(pIn, &title, &tail) ){ |
| 1358 | blob_appendf(pOut, "%s\n", blob_str(&title)); |
| 1359 | wiki_convert(&tail, &html, 0); |
| 1360 | blob_reset(&tail); |
| 1361 | }else{ |
| 1362 | blob_append(pOut, "\n", 1); |
| 1363 | wiki_convert(pIn, &html, 0); |
| 1364 | } |
| 1365 | } |
| 1366 | html_to_plaintext(blob_str(&html), pOut); |
| 1367 | }else if( fossil_strcmp(zMimetype,"text/x-markdown")==0 ){ |
| 1368 | markdown_to_html(pIn, blob_size(&title) ? NULL : &title, &html); |
| 1369 | }else if( fossil_strcmp(zMimetype,"text/html")==0 ){ |
| 1370 | if( blob_size(&title)==0 ) doc_is_embedded_html(pIn, &title); |
| 1371 | pHtml = pIn; |
| 1372 | } |
| 1373 | blob_appendf(pOut, "%s\n", blob_str(&title)); |
| 1374 | if( blob_size(pHtml) ){ |
| 1375 | html_to_plaintext(blob_str(pHtml), pOut); |
| 1376 | }else{ |
| 1377 | blob_append(pOut, blob_buffer(pIn), blob_size(pIn)); |
| 1378 | } |
| 1379 | blob_reset(&html); |
| 1380 | blob_reset(&title); |
| 1381 | } |
| @@ -1400,11 +1408,11 @@ | |
| 1408 | blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i)); |
| 1409 | }else{ |
| 1410 | Blob txt; |
| 1411 | blob_init(&txt, db_column_text(pQuery,i), -1); |
| 1412 | blob_appendf(pAccum, "%s: ", zColName); |
| 1413 | get_stext_by_mimetype(&txt, zMime, NULL, pAccum); |
| 1414 | blob_append(pAccum, " |", 2); |
| 1415 | blob_reset(&txt); |
| 1416 | } |
| 1417 | } |
| 1418 | } |
| @@ -1439,11 +1447,11 @@ | |
| 1447 | switch( cType ){ |
| 1448 | case 'd': { /* Documents */ |
| 1449 | Blob doc; |
| 1450 | content_get(rid, &doc); |
| 1451 | blob_to_utf8_no_bom(&doc, 0); |
| 1452 | get_stext_by_mimetype(&doc, mimetype_from_name(zName), NULL, pOut); |
| 1453 | blob_reset(&doc); |
| 1454 | break; |
| 1455 | } |
| 1456 | case 'f': /* Forum messages */ |
| 1457 | case 'e': /* Tech Notes */ |
| @@ -1461,11 +1469,11 @@ | |
| 1469 | blob_appendf(&wiki, "From %s:\n\n%s", pWiki->zUser, pWiki->zWiki); |
| 1470 | }else{ |
| 1471 | blob_init(&wiki, pWiki->zWiki, -1); |
| 1472 | } |
| 1473 | get_stext_by_mimetype(&wiki, wiki_filter_mimetypes(pWiki->zMimetype), |
| 1474 | cType=='w' ? pWiki->zWikiTitle : NULL, pOut); |
| 1475 | blob_reset(&wiki); |
| 1476 | manifest_destroy(pWiki); |
| 1477 | break; |
| 1478 | } |
| 1479 | case 'c': { /* Check-in Comments */ |
| @@ -1491,11 +1499,11 @@ | |
| 1499 | db_column_blob(&q, 0, pOut); |
| 1500 | }else{ |
| 1501 | Blob x; |
| 1502 | blob_init(&x,0,0); |
| 1503 | db_column_blob(&q, 0, &x); |
| 1504 | get_stext_by_mimetype(&x, "text/x-fossil-wiki", NULL, pOut); |
| 1505 | blob_reset(&x); |
| 1506 | } |
| 1507 | } |
| 1508 | db_reset(&q); |
| 1509 | break; |
| @@ -1602,11 +1610,11 @@ | |
| 1610 | Blob in, out; |
| 1611 | db_find_and_open_repository(0,0); |
| 1612 | if( g.argc!=4 ) usage("FILENAME MIMETYPE"); |
| 1613 | blob_read_from_file(&in, g.argv[2], ExtFILE); |
| 1614 | blob_init(&out, 0, 0); |
| 1615 | get_stext_by_mimetype(&in, g.argv[3], NULL, &out); |
| 1616 | fossil_print("%s\n",blob_str(&out)); |
| 1617 | blob_reset(&in); |
| 1618 | blob_reset(&out); |
| 1619 | } |
| 1620 | |
| 1621 |