Fossil SCM

When extracting search text from tickets, use the title column for the title and pay attention to mimetypes when translating.

drh 2015-02-13 22:03 UTC search-enhancements
Commit b552f55b1f584056aeff3872a80b22f96f8792b6
1 file changed +33 -13
+33 -13
--- src/search.c
+++ src/search.c
@@ -1034,22 +1034,39 @@
10341034
10351035
/*
10361036
** Query pQuery is pointing at a single row of output. Append a text
10371037
** representation of every text-compatible column to pAccum.
10381038
*/
1039
-static void append_all_ticket_fields(Blob *pAccum, Stmt *pQuery){
1039
+static void append_all_ticket_fields(Blob *pAccum, Stmt *pQuery, int iTitle){
10401040
int n = db_column_count(pQuery);
10411041
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
+ }
10421049
for(i=0; i<n; i++){
10431050
const char *zColName = db_column_name(pQuery,i);
1051
+ int eType = db_column_type(pQuery,i);
1052
+ if( i==iTitle ) continue;
10441053
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);
10511068
}
10521069
}
10531070
}
10541071
10551072
@@ -1126,30 +1143,33 @@
11261143
db_reset(&q);
11271144
break;
11281145
}
11291146
case 't': { /* Tickets */
11301147
static Stmt q1;
1131
- Blob raw;
1148
+ static int iTitle = -1;
11321149
db_static_prepare(&q1, "SELECT * FROM ticket WHERE tkt_id=:rid");
1133
- blob_init(&raw,0,0);
11341150
db_bind_int(&q1, ":rid", rid);
11351151
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);
11371159
}
11381160
db_reset(&q1);
11391161
if( db_table_exists("repository","ticketchng") ){
11401162
static Stmt q2;
11411163
db_static_prepare(&q2, "SELECT * FROM ticketchng WHERE tkt_id=:rid"
11421164
" ORDER BY tkt_mtime");
11431165
db_bind_int(&q2, ":rid", rid);
11441166
while( db_step(&q2)==SQLITE_ROW ){
1145
- append_all_ticket_fields(&raw, &q2);
1167
+ append_all_ticket_fields(pOut, &q2, -1);
11461168
}
11471169
db_reset(&q2);
11481170
}
1149
- html_to_plaintext(blob_str(&raw), pOut);
1150
- blob_reset(&raw);
11511171
break;
11521172
}
11531173
}
11541174
}
11551175
11561176
--- 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

Keyboard Shortcuts

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