Fossil SCM

Add the "search" command to the command-line interface. This command is still experimental. Currently it only search the timeline.

drh 2009-11-08 21:41 trunk
Commit 20600107f137736581fa9a54d8bb973130503d0e
1 file changed +20 -17
+20 -17
--- src/search.c
+++ src/search.c
@@ -172,20 +172,21 @@
172172
}
173173
174174
/*
175175
** Testing the search function.
176176
**
177
-** COMMAND: test-search
178
-** %fossil test-search pattern...
177
+** COMMAND: search
178
+** %fossil search pattern...
179179
**
180
-** search for check-ins matching the pattern.
180
+** Search for timeline entrys matching the pattern.
181181
*/
182
-void search_test(void){
182
+void search_cmd(void){
183183
Search *p;
184184
Blob pattern;
185185
int i;
186186
Stmt q;
187
+ int iBest;
187188
188189
db_must_be_within_tree();
189190
if( g.argc<2 ) return;
190191
blob_init(&pattern, g.argv[2], -1);
191192
for(i=3; i<g.argc; i++){
@@ -194,21 +195,23 @@
194195
p = search_init(blob_str(&pattern));
195196
blob_reset(&pattern);
196197
search_sql_setup(p);
197198
198199
db_multi_exec(
199
- "CREATE TEMP TABLE srch(x,text);"
200
- "INSERT INTO srch(text) SELECT coalesce(ecomment,comment) FROM event;"
201
- "UPDATE srch SET x=score(text);"
200
+ "CREATE TEMP TABLE srch(rid,uuid,date,comment,x);"
201
+ "CREATE INDEX srch_idx1 ON srch(x);"
202
+ "INSERT INTO srch(rid,uuid,date,comment,x)"
203
+ " SELECT blob.rid, uuid, datetime(event.mtime, 'localtime'),"
204
+ " coalesce(ecomment,comment),"
205
+ " score(coalesce(ecomment,comment)) AS y"
206
+ " FROM event, blob"
207
+ " WHERE blob.rid=event.objid AND y>0;"
208
+ );
209
+ iBest = db_int(0, "SELECT max(x) FROM srch");
210
+ db_prepare(&q,
211
+ "SELECT rid, uuid, date, comment, 0, 0 FROM srch"
212
+ " WHERE x>%d ORDER BY x DESC, date DESC",
213
+ iBest/3
202214
);
203
- db_prepare(&q, "SELECT x, text FROM srch WHERE x>0 ORDER BY x DESC");
204
- while( db_step(&q)==SQLITE_ROW ){
205
- int score = db_column_int(&q, 0);
206
- const char *z = db_column_text(&q, 1);
207
-
208
- score = search_score(p, z);
209
- if( score ){
210
- printf("%5d: %s\n", score, z);
211
- }
212
- }
215
+ print_timeline(&q, 1000);
213216
db_finalize(&q);
214217
}
215218
--- src/search.c
+++ src/search.c
@@ -172,20 +172,21 @@
172 }
173
174 /*
175 ** Testing the search function.
176 **
177 ** COMMAND: test-search
178 ** %fossil test-search pattern...
179 **
180 ** search for check-ins matching the pattern.
181 */
182 void search_test(void){
183 Search *p;
184 Blob pattern;
185 int i;
186 Stmt q;
 
187
188 db_must_be_within_tree();
189 if( g.argc<2 ) return;
190 blob_init(&pattern, g.argv[2], -1);
191 for(i=3; i<g.argc; i++){
@@ -194,21 +195,23 @@
194 p = search_init(blob_str(&pattern));
195 blob_reset(&pattern);
196 search_sql_setup(p);
197
198 db_multi_exec(
199 "CREATE TEMP TABLE srch(x,text);"
200 "INSERT INTO srch(text) SELECT coalesce(ecomment,comment) FROM event;"
201 "UPDATE srch SET x=score(text);"
 
 
 
 
 
 
 
 
 
 
 
202 );
203 db_prepare(&q, "SELECT x, text FROM srch WHERE x>0 ORDER BY x DESC");
204 while( db_step(&q)==SQLITE_ROW ){
205 int score = db_column_int(&q, 0);
206 const char *z = db_column_text(&q, 1);
207
208 score = search_score(p, z);
209 if( score ){
210 printf("%5d: %s\n", score, z);
211 }
212 }
213 db_finalize(&q);
214 }
215
--- src/search.c
+++ src/search.c
@@ -172,20 +172,21 @@
172 }
173
174 /*
175 ** Testing the search function.
176 **
177 ** COMMAND: search
178 ** %fossil search pattern...
179 **
180 ** Search for timeline entrys matching the pattern.
181 */
182 void search_cmd(void){
183 Search *p;
184 Blob pattern;
185 int i;
186 Stmt q;
187 int iBest;
188
189 db_must_be_within_tree();
190 if( g.argc<2 ) return;
191 blob_init(&pattern, g.argv[2], -1);
192 for(i=3; i<g.argc; i++){
@@ -194,21 +195,23 @@
195 p = search_init(blob_str(&pattern));
196 blob_reset(&pattern);
197 search_sql_setup(p);
198
199 db_multi_exec(
200 "CREATE TEMP TABLE srch(rid,uuid,date,comment,x);"
201 "CREATE INDEX srch_idx1 ON srch(x);"
202 "INSERT INTO srch(rid,uuid,date,comment,x)"
203 " SELECT blob.rid, uuid, datetime(event.mtime, 'localtime'),"
204 " coalesce(ecomment,comment),"
205 " score(coalesce(ecomment,comment)) AS y"
206 " FROM event, blob"
207 " WHERE blob.rid=event.objid AND y>0;"
208 );
209 iBest = db_int(0, "SELECT max(x) FROM srch");
210 db_prepare(&q,
211 "SELECT rid, uuid, date, comment, 0, 0 FROM srch"
212 " WHERE x>%d ORDER BY x DESC, date DESC",
213 iBest/3
214 );
215 print_timeline(&q, 1000);
 
 
 
 
 
 
 
 
 
216 db_finalize(&q);
217 }
218

Keyboard Shortcuts

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