981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
|
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
|
+
+
+
+
-
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
|
style_footer();
}
/*
** This is a helper function for search_stext(). Writing into pOut
** the search text obtained from pIn according to zMimetype.
**
** The title of the document is the first line of text. All subsequent
** lines are the body. If the document has no title, the first line
** is blank.
*/
static void get_stext_by_mimetype(
Blob *pIn,
const char *zMimetype,
Blob *pOut
){
Blob html, title;
Blob html, title, tail;
blob_init(&html, 0, 0);
blob_init(&title, 0, 0);
if( zMimetype==0 ) zMimetype = "text/plain";
if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")==0 ){
Blob tail;
blob_init(&tail, 0, 0);
if( wiki_find_title(pIn, &title, &tail) ){
blob_appendf(pOut, "%s\n", blob_str(&title));
wiki_convert(&tail, &html, 0);
blob_reset(&tail);
}else{
blob_append(pOut, "\n", 1);
wiki_convert(pIn, &html, 0);
wiki_convert(pIn, &html, 0);
}
html_to_plaintext(blob_str(&html), pOut);
}else if( fossil_strcmp(zMimetype,"text/x-markdown")==0 ){
markdown_to_html(pIn, &title, &html);
if( blob_size(&title) ){
blob_appendf(pOut, "%s\n", blob_str(&title));
}else{
blob_append(pOut, "\n", 1);
}
html_to_plaintext(blob_str(&html), pOut);
}else if( fossil_strcmp(zMimetype,"text/html")==0 ){
if( doc_is_embedded_html(pIn, &title) ){
blob_appendf(pOut, "%s\n", blob_str(&title));
}
html_to_plaintext(blob_str(pIn), pOut);
}else{
*pOut = *pIn;
blob_init(pIn, 0, 0);
}
blob_reset(&html);
blob_reset(&title);
|
1052
1053
1054
1055
1056
1057
1058
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
|
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
|
-
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
|
const char *zName, /* Auxiliary information */
Blob *pOut /* OUT: Initialize to the search text */
){
blob_init(pOut, 0, 0);
switch( cType ){
case 'd': { /* Documents */
Blob doc;
content_get(rid, &doc);
content_get(rid, &doc);
blob_to_utf8_no_bom(&doc, 0);
get_stext_by_mimetype(&doc, mimetype_from_name(zName), pOut);
blob_reset(&doc);
break;
}
case 'w': { /* Wiki */
Manifest *pWiki = manifest_get(rid, CFTYPE_WIKI,0);
Blob wiki;
if( pWiki==0 ) break;
blob_init(&wiki, pWiki->zWiki, -1);
get_stext_by_mimetype(&wiki, wiki_filter_mimetypes(pWiki->zMimetype),
pOut);
blob_reset(&wiki);
manifest_destroy(pWiki);
break;
}
case 'c': { /* Check-in Comments */
static Stmt q;
static int isPlainText = -1;
db_static_prepare(&q,
"SELECT coalesce(ecomment,comment)"
" ||' (user: '||coalesce(euser,user,'?')"
" ||', tags: '||"
" (SELECT group_concat(substr(tag.tagname,5),',')"
" FROM tag, tagxref"
" WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid"
" AND tagxref.rid=event.objid AND tagxref.tagtype>0)"
" ||')'"
" FROM event WHERE objid=:x AND type='ci'");
if( isPlainText<0 ){
isPlainText = db_get_boolean("timeline-plaintext",0);
}
db_bind_int(&q, ":x", rid);
if( db_step(&q)==SQLITE_ROW ){
blob_append(pOut, "\n", 1);
if( isPlainText ){
db_column_blob(&q, 0, pOut);
blob_append(pOut, "\n", 1);
db_column_blob(&q, 0, pOut);
}else{
Blob x;
blob_init(&x,0,0);
db_column_blob(&q, 0, &x);
get_stext_by_mimetype(&x, "text/x-fossil-wiki", pOut);
blob_reset(&x);
}
}
db_reset(&q);
break;
}
case 't': { /* Tickets */
static Stmt q1;
Blob raw;
|
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
|
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
Blob out;
db_find_and_open_repository(0,0);
if( g.argc!=5 ) usage("TYPE RID NAME");
search_stext(g.argv[2][0], atoi(g.argv[3]), g.argv[4], &out);
fossil_print("%s\n",blob_str(&out));
blob_reset(&out);
}
/*
** COMMAND: test-convert-stext
**
** Usage: fossil test-convert-stext FILE MIMETYPE
**
** Read the content of FILE and convert it to stext according to MIMETYPE.
** Send the result to standard output.
*/
void test_convert_stext(void){
Blob in, out;
db_find_and_open_repository(0,0);
if( g.argc!=4 ) usage("FILENAME MIMETYPE");
blob_read_from_file(&in, g.argv[2]);
blob_init(&out, 0, 0);
get_stext_by_mimetype(&in, g.argv[3], &out);
fossil_print("%s\n",blob_str(&out));
blob_reset(&in);
blob_reset(&out);
}
/* The schema for the full-text index
*/
static const char zFtsSchema[] =
@ -- One entry for each possible search result
@ CREATE TABLE IF NOT EXISTS "%w".ftsdocs(
@ rowid INTEGER PRIMARY KEY, -- Maps to the ftsidx.docid
|