Fossil SCM
When extracting search text from tickets, use the title column for the title and pay attention to mimetypes when translating.
Commit
b552f55b1f584056aeff3872a80b22f96f8792b6
Parent
23c86b503f0f033…
1 file changed
+33
-13
+33
-13
| --- src/search.c | ||
| +++ src/search.c | ||
| @@ -1034,22 +1034,39 @@ | ||
| 1034 | 1034 | |
| 1035 | 1035 | /* |
| 1036 | 1036 | ** Query pQuery is pointing at a single row of output. Append a text |
| 1037 | 1037 | ** representation of every text-compatible column to pAccum. |
| 1038 | 1038 | */ |
| 1039 | -static void append_all_ticket_fields(Blob *pAccum, Stmt *pQuery){ | |
| 1039 | +static void append_all_ticket_fields(Blob *pAccum, Stmt *pQuery, int iTitle){ | |
| 1040 | 1040 | int n = db_column_count(pQuery); |
| 1041 | 1041 | int i; |
| 1042 | + const char *zMime = 0; | |
| 1043 | + if( iTitle>=0 ){ | |
| 1044 | + if( db_column_type(pQuery,iTitle)==SQLITE_TEXT ){ | |
| 1045 | + blob_append(pAccum, db_column_text(pQuery,iTitle), -1); | |
| 1046 | + } | |
| 1047 | + blob_append(pAccum, "\n", 1); | |
| 1048 | + } | |
| 1042 | 1049 | for(i=0; i<n; i++){ |
| 1043 | 1050 | const char *zColName = db_column_name(pQuery,i); |
| 1051 | + int eType = db_column_type(pQuery,i); | |
| 1052 | + if( i==iTitle ) continue; | |
| 1044 | 1053 | if( fossil_strnicmp(zColName,"tkt_",4)==0 ) continue; |
| 1045 | - if( fossil_stricmp(zColName,"mimetype")==0 ) continue; | |
| 1046 | - switch( db_column_type(pQuery,i) ){ | |
| 1047 | - case SQLITE_INTEGER: | |
| 1048 | - case SQLITE_FLOAT: | |
| 1049 | - case SQLITE_TEXT: | |
| 1050 | - blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i)); | |
| 1054 | + if( fossil_strnicmp(zColName,"private_",8)==0 ) continue; | |
| 1055 | + if( eType==SQLITE_BLOB || eType==SQLITE_NULL ) continue; | |
| 1056 | + if( fossil_stricmp(zColName,"mimetype")==0 ){ | |
| 1057 | + zMime = db_column_text(pQuery,i); | |
| 1058 | + if( fossil_strcmp(zMime,"text/plain")==0 ) zMime = 0; | |
| 1059 | + }else if( zMime==0 || eType!=SQLITE_TEXT ){ | |
| 1060 | + blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i)); | |
| 1061 | + }else{ | |
| 1062 | + Blob txt; | |
| 1063 | + blob_init(&txt, db_column_text(pQuery,i), -1); | |
| 1064 | + blob_appendf(pAccum, "%s: ", zColName); | |
| 1065 | + get_stext_by_mimetype(&txt, zMime, pAccum); | |
| 1066 | + blob_append(pAccum, " |", 2); | |
| 1067 | + blob_reset(&txt); | |
| 1051 | 1068 | } |
| 1052 | 1069 | } |
| 1053 | 1070 | } |
| 1054 | 1071 | |
| 1055 | 1072 | |
| @@ -1126,30 +1143,33 @@ | ||
| 1126 | 1143 | db_reset(&q); |
| 1127 | 1144 | break; |
| 1128 | 1145 | } |
| 1129 | 1146 | case 't': { /* Tickets */ |
| 1130 | 1147 | static Stmt q1; |
| 1131 | - Blob raw; | |
| 1148 | + static int iTitle = -1; | |
| 1132 | 1149 | db_static_prepare(&q1, "SELECT * FROM ticket WHERE tkt_id=:rid"); |
| 1133 | - blob_init(&raw,0,0); | |
| 1134 | 1150 | db_bind_int(&q1, ":rid", rid); |
| 1135 | 1151 | if( db_step(&q1)==SQLITE_ROW ){ |
| 1136 | - append_all_ticket_fields(&raw, &q1); | |
| 1152 | + if( iTitle<0 ){ | |
| 1153 | + int n = db_column_count(&q1); | |
| 1154 | + for(iTitle=0; iTitle<n; iTitle++){ | |
| 1155 | + if( fossil_stricmp(db_column_name(&q1,iTitle),"title")==0 ) break; | |
| 1156 | + } | |
| 1157 | + } | |
| 1158 | + append_all_ticket_fields(pOut, &q1, iTitle); | |
| 1137 | 1159 | } |
| 1138 | 1160 | db_reset(&q1); |
| 1139 | 1161 | if( db_table_exists("repository","ticketchng") ){ |
| 1140 | 1162 | static Stmt q2; |
| 1141 | 1163 | db_static_prepare(&q2, "SELECT * FROM ticketchng WHERE tkt_id=:rid" |
| 1142 | 1164 | " ORDER BY tkt_mtime"); |
| 1143 | 1165 | db_bind_int(&q2, ":rid", rid); |
| 1144 | 1166 | while( db_step(&q2)==SQLITE_ROW ){ |
| 1145 | - append_all_ticket_fields(&raw, &q2); | |
| 1167 | + append_all_ticket_fields(pOut, &q2, -1); | |
| 1146 | 1168 | } |
| 1147 | 1169 | db_reset(&q2); |
| 1148 | 1170 | } |
| 1149 | - html_to_plaintext(blob_str(&raw), pOut); | |
| 1150 | - blob_reset(&raw); | |
| 1151 | 1171 | break; |
| 1152 | 1172 | } |
| 1153 | 1173 | } |
| 1154 | 1174 | } |
| 1155 | 1175 | |
| 1156 | 1176 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -1034,22 +1034,39 @@ | |
| 1034 | |
| 1035 | /* |
| 1036 | ** Query pQuery is pointing at a single row of output. Append a text |
| 1037 | ** representation of every text-compatible column to pAccum. |
| 1038 | */ |
| 1039 | static void append_all_ticket_fields(Blob *pAccum, Stmt *pQuery){ |
| 1040 | int n = db_column_count(pQuery); |
| 1041 | int i; |
| 1042 | for(i=0; i<n; i++){ |
| 1043 | const char *zColName = db_column_name(pQuery,i); |
| 1044 | if( fossil_strnicmp(zColName,"tkt_",4)==0 ) continue; |
| 1045 | if( fossil_stricmp(zColName,"mimetype")==0 ) continue; |
| 1046 | switch( db_column_type(pQuery,i) ){ |
| 1047 | case SQLITE_INTEGER: |
| 1048 | case SQLITE_FLOAT: |
| 1049 | case SQLITE_TEXT: |
| 1050 | blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i)); |
| 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | |
| @@ -1126,30 +1143,33 @@ | |
| 1126 | db_reset(&q); |
| 1127 | break; |
| 1128 | } |
| 1129 | case 't': { /* Tickets */ |
| 1130 | static Stmt q1; |
| 1131 | Blob raw; |
| 1132 | db_static_prepare(&q1, "SELECT * FROM ticket WHERE tkt_id=:rid"); |
| 1133 | blob_init(&raw,0,0); |
| 1134 | db_bind_int(&q1, ":rid", rid); |
| 1135 | if( db_step(&q1)==SQLITE_ROW ){ |
| 1136 | append_all_ticket_fields(&raw, &q1); |
| 1137 | } |
| 1138 | db_reset(&q1); |
| 1139 | if( db_table_exists("repository","ticketchng") ){ |
| 1140 | static Stmt q2; |
| 1141 | db_static_prepare(&q2, "SELECT * FROM ticketchng WHERE tkt_id=:rid" |
| 1142 | " ORDER BY tkt_mtime"); |
| 1143 | db_bind_int(&q2, ":rid", rid); |
| 1144 | while( db_step(&q2)==SQLITE_ROW ){ |
| 1145 | append_all_ticket_fields(&raw, &q2); |
| 1146 | } |
| 1147 | db_reset(&q2); |
| 1148 | } |
| 1149 | html_to_plaintext(blob_str(&raw), pOut); |
| 1150 | blob_reset(&raw); |
| 1151 | break; |
| 1152 | } |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -1034,22 +1034,39 @@ | |
| 1034 | |
| 1035 | /* |
| 1036 | ** Query pQuery is pointing at a single row of output. Append a text |
| 1037 | ** representation of every text-compatible column to pAccum. |
| 1038 | */ |
| 1039 | static void append_all_ticket_fields(Blob *pAccum, Stmt *pQuery, int iTitle){ |
| 1040 | int n = db_column_count(pQuery); |
| 1041 | int i; |
| 1042 | const char *zMime = 0; |
| 1043 | if( iTitle>=0 ){ |
| 1044 | if( db_column_type(pQuery,iTitle)==SQLITE_TEXT ){ |
| 1045 | blob_append(pAccum, db_column_text(pQuery,iTitle), -1); |
| 1046 | } |
| 1047 | blob_append(pAccum, "\n", 1); |
| 1048 | } |
| 1049 | for(i=0; i<n; i++){ |
| 1050 | const char *zColName = db_column_name(pQuery,i); |
| 1051 | int eType = db_column_type(pQuery,i); |
| 1052 | if( i==iTitle ) continue; |
| 1053 | if( fossil_strnicmp(zColName,"tkt_",4)==0 ) continue; |
| 1054 | if( fossil_strnicmp(zColName,"private_",8)==0 ) continue; |
| 1055 | if( eType==SQLITE_BLOB || eType==SQLITE_NULL ) continue; |
| 1056 | if( fossil_stricmp(zColName,"mimetype")==0 ){ |
| 1057 | zMime = db_column_text(pQuery,i); |
| 1058 | if( fossil_strcmp(zMime,"text/plain")==0 ) zMime = 0; |
| 1059 | }else if( zMime==0 || eType!=SQLITE_TEXT ){ |
| 1060 | blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i)); |
| 1061 | }else{ |
| 1062 | Blob txt; |
| 1063 | blob_init(&txt, db_column_text(pQuery,i), -1); |
| 1064 | blob_appendf(pAccum, "%s: ", zColName); |
| 1065 | get_stext_by_mimetype(&txt, zMime, pAccum); |
| 1066 | blob_append(pAccum, " |", 2); |
| 1067 | blob_reset(&txt); |
| 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | |
| @@ -1126,30 +1143,33 @@ | |
| 1143 | db_reset(&q); |
| 1144 | break; |
| 1145 | } |
| 1146 | case 't': { /* Tickets */ |
| 1147 | static Stmt q1; |
| 1148 | static int iTitle = -1; |
| 1149 | db_static_prepare(&q1, "SELECT * FROM ticket WHERE tkt_id=:rid"); |
| 1150 | db_bind_int(&q1, ":rid", rid); |
| 1151 | if( db_step(&q1)==SQLITE_ROW ){ |
| 1152 | if( iTitle<0 ){ |
| 1153 | int n = db_column_count(&q1); |
| 1154 | for(iTitle=0; iTitle<n; iTitle++){ |
| 1155 | if( fossil_stricmp(db_column_name(&q1,iTitle),"title")==0 ) break; |
| 1156 | } |
| 1157 | } |
| 1158 | append_all_ticket_fields(pOut, &q1, iTitle); |
| 1159 | } |
| 1160 | db_reset(&q1); |
| 1161 | if( db_table_exists("repository","ticketchng") ){ |
| 1162 | static Stmt q2; |
| 1163 | db_static_prepare(&q2, "SELECT * FROM ticketchng WHERE tkt_id=:rid" |
| 1164 | " ORDER BY tkt_mtime"); |
| 1165 | db_bind_int(&q2, ":rid", rid); |
| 1166 | while( db_step(&q2)==SQLITE_ROW ){ |
| 1167 | append_all_ticket_fields(pOut, &q2, -1); |
| 1168 | } |
| 1169 | db_reset(&q2); |
| 1170 | } |
| 1171 | break; |
| 1172 | } |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 |