Fossil

Check-in [20600107]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the "search" command to the command-line interface. This command is still experimental. Currently it only search the timeline.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 20600107f137736581fa9a54d8bb973130503d0e
User & Date: drh 2009-11-08 21:41:09
Context
2009-11-09
00:58
On the "timeline" command, if a YYYY-MM-DD date string is entered without the "before" keyword, then show all changes on the date given. check-in: 0239325f user: drh tags: trunk
2009-11-08
21:41
Add the "search" command to the command-line interface. This command is still experimental. Currently it only search the timeline. check-in: 20600107 user: drh tags: trunk
2009-11-06
14:15
Add the --once command-line option to push, pull, and sync. Ticket [2aaa8042caec] check-in: 5153d618 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/search.c.

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214


  sqlite3_create_function(g.db, "score", 1, SQLITE_UTF8, p,
     search_score_sqlfunc, 0, 0);
}

/*
** Testing the search function.
**
** COMMAND: test-search
** %fossil test-search pattern...
**
** search for check-ins matching the pattern.
*/
void search_test(void){
  Search *p;
  Blob pattern;
  int i;
  Stmt q;


  db_must_be_within_tree();
  if( g.argc<2 ) return;
  blob_init(&pattern, g.argv[2], -1);
  for(i=3; i<g.argc; i++){
    blob_appendf(&pattern, " %s", g.argv[i]);
  }
  p = search_init(blob_str(&pattern));
  blob_reset(&pattern);
  search_sql_setup(p);

  db_multi_exec(
     "CREATE TEMP TABLE srch(x,text);"
     "INSERT INTO srch(text) SELECT coalesce(ecomment,comment) FROM event;"
     "UPDATE srch SET x=score(text);"
  );
  db_prepare(&q, "SELECT x, text FROM srch WHERE x>0 ORDER BY x DESC");
  while( db_step(&q)==SQLITE_ROW ){
    int score = db_column_int(&q, 0);
    const char *z = db_column_text(&q, 1);

    score = search_score(p, z);
    if( score ){
      printf("%5d: %s\n", score, z);
    }
  }
  db_finalize(&q);
}









|
|

|

|




>












|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
  sqlite3_create_function(g.db, "score", 1, SQLITE_UTF8, p,
     search_score_sqlfunc, 0, 0);
}

/*
** Testing the search function.
**
** COMMAND: search
** %fossil search pattern...
**
** Search for timeline entrys matching the pattern.
*/
void search_cmd(void){
  Search *p;
  Blob pattern;
  int i;
  Stmt q;
  int iBest;

  db_must_be_within_tree();
  if( g.argc<2 ) return;
  blob_init(&pattern, g.argv[2], -1);
  for(i=3; i<g.argc; i++){
    blob_appendf(&pattern, " %s", g.argv[i]);
  }
  p = search_init(blob_str(&pattern));
  blob_reset(&pattern);
  search_sql_setup(p);

  db_multi_exec(
     "CREATE TEMP TABLE srch(rid,uuid,date,comment,x);"
     "CREATE INDEX srch_idx1 ON srch(x);"
     "INSERT INTO srch(rid,uuid,date,comment,x)"
     "   SELECT blob.rid, uuid, datetime(event.mtime, 'localtime'),"
     "          coalesce(ecomment,comment),"
     "          score(coalesce(ecomment,comment)) AS y"
     "     FROM event, blob"
     "    WHERE blob.rid=event.objid AND y>0;"
  );
  iBest = db_int(0, "SELECT max(x) FROM srch");
  db_prepare(&q, 
    "SELECT rid, uuid, date, comment, 0, 0 FROM srch"
    " WHERE x>%d ORDER BY x DESC, date DESC",
    iBest/3
  );
  print_timeline(&q, 1000);
  db_finalize(&q);
}