#!/usr/bin/tclsh.docsrc #### Import of wapp.tcl INCLUDE wapp.tcl #### End of wapp.tcl # Generate all header content for the output document # proc search_header {} { wapp-trim { DOCHEAD {Search SQLite Documentation} {} } } #------------------------------------------------------------------------- # Add an entry to the log database for the current query. Which # returns $nRes results. # proc search_add_log_entry {nRes} { if {[wapp-param-exists donotlog]} return sqlite3 db2 [file dir [wapp-param SCRIPT_FILENAME]]/search.d/searchlog.db db2 timeout 10000 set ip [wapp-param REMOTE_ADDR] set query [wapp-param q] db2 eval { PRAGMA synchronous=OFF; PRAGMA journal_mode=OFF; BEGIN; CREATE TABLE IF NOT EXISTS log( ip, -- IP query was made from query, -- Fts5 query string nres, -- Number of results timestamp DEFAULT CURRENT_TIMESTAMP ); INSERT INTO log(ip, query, nres) VALUES($ip, $query, $nRes); COMMIT; } db2 close } #------------------------------------------------------------------------- # This command is similar to the builtin Tcl [time] command, except that # it only ever runs the supplied script once. Also, instead of returning # a string like "xxx microseconds per iteration", it returns "x.yy ms" or # "x.yy s", depending on the magnitude of the time spent running the # command. For example: # # % ttime {after 1500} # 1.50 s # % ttime {after 45} # 45.02 ms # proc ttime {script} { set t [lindex [time [list uplevel $script]] 0] if {$t>1000000} { return [format "%.2f s" [expr {$t/1000000.0}]] } return [format "%.2f ms" [expr {$t/1000.0}]] } #----------------------------------------------------------------------- # Do a search of the change log # proc searchchanges {} { set q [wapp-param q] if {$q==""} {return {}} set open {} set close {} set query { SELECT url, version, idx, highlight(change, 3, $open, $close) AS text FROM change($q) ORDER BY rowid ASC } wapp-trim {
Change log entries mentioning: %html($q)
%html($version) |
|
You can also see the entire changelog as a single page if you wish.
No Results for: %html($q)\n} } # HTML markup used to highlight keywords within FTS5 generated snippets. # set open {} set close {} set ellipsis { ... } # Grab the required data # db eval [string map [list %LIST% [join $lRowid ,]] { SELECT rowid AS parentid, snippet(page, 0, $open, $close, $ellipsis, 6) AS s_apis, snippet(page, 2, $open, $close, '', 40) AS s_title1, snippet(page, 3, $open, $close, $ellipsis, 40) AS s_title2, snippet(page, 4, $open, $close, $ellipsis, 40) AS s_content, url, rank FROM page($q) WHERE rowid IN (%LIST%) }] X { foreach k [array names X] { set data($X(parentid),$k) [set X($k)] } } set i1 [expr {$iStart+1}] set i2 [expr {($nRes < $iStart+10) ? $nRes : $iStart+10}] wapp-trim {
%unsafe($s_title1)
(%url($url))
%unsafe($s_apis)
%unsafe($s_content)
|
}
}
wapp-subst {
\n} for {set i 0} {$i < 10 && ($i*10)<$nRes} {incr i} { set style $s([expr {($iStart/10)==$i}]) wapp-trim { %html([expr $i+1]) } } wapp-subst {
%html([wapp-debug-env])} return } # When running using the built-in webserver in Wapp (in other words, # when not running as CGI) any filename that contains a "." loads # directly from the filesystem. if {[string match *//127.0.0.1:* [wapp-param BASE_URL]] && [string match *.* [wapp-param PATH_INFO]] } { set altfile [file dir [wapp-param SCRIPT_FILENAME]][wapp-param PATH_INFO] set fd [open $altfile rb] fconfigure $fd -translation binary wapp-unsafe [read $fd] close $fd switch -glob -- $altfile { *.html { wapp-mimetype text/html } *.css { wapp-mimetype text/css } *.gif { wapp-mimetype image/gif } } return } search_header sqlite3 db [file dir [wapp-param SCRIPT_FILENAME]]/search.d/search.db set searchType [wapp-param s d] if {$searchType=="c"} { set cmd searchchanges } else { set cmd searchresults } db transaction { set t [ttime {$cmd}] } wapp-trim {
Page generated by FTS5 in about %html($t).