Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Store the search database, search-log database and search "admin" script in a separate directory. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
28aa410b46b07feeef76eeb4533dee39 |
User & Date: | dan 2016-08-31 06:35:46.930 |
Context
2016-08-31
| ||
07:00 | Fix a build error in the previous commit. (check-in: 1e433b2be3 user: dan tags: trunk) | |
06:35 | Store the search database, search-log database and search "admin" script in a separate directory. (check-in: 28aa410b46 user: dan tags: trunk) | |
2016-08-30
| ||
17:05 | Tweak the search engines ranking algorithm slightly. Add a logging database and a way for admins to view the most recent queries. (check-in: 4dd2793f98 user: dan tags: trunk) | |
Changes
Changes to main.mk.
︙ | ︙ | |||
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | # SFLAGS = $(TCLINC) -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_FTS5 -DSQLITE_TCLMD5 -DTCLSH -Dmain=xmain $(TCLSH): $(SSRC) $(CC) -O2 -o $@ -I. $(SFLAGS) $(SSRC) $(TCLFLAGS) searchdb: $(TCLSH) ./$(TCLSH) $(DOC)/search/buildsearchdb.tcl cp $(DOC)/document_header.tcl doc/document_header.tcl cp $(DOC)/search/search.tcl doc/search chmod +x doc/search always: clean: rm -rf $(TCLSH) doc sqlite3.h | > > > > | 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | # SFLAGS = $(TCLINC) -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_FTS5 -DSQLITE_TCLMD5 -DTCLSH -Dmain=xmain $(TCLSH): $(SSRC) $(CC) -O2 -o $@ -I. $(SFLAGS) $(SSRC) $(TCLFLAGS) searchdb: $(TCLSH) mkdir doc/search.d/ ./$(TCLSH) $(DOC)/search/buildsearchdb.tcl cp $(DOC)/document_header.tcl doc/document_header.tcl cp $(DOC)/document_header.tcl doc/search.d/document_header.tcl cp $(DOC)/search/search.tcl doc/search chmod +x doc/search cp $(DOC)/search/search.tcl doc/search.d/admin chmod +x doc/search.d/admin always: clean: rm -rf $(TCLSH) doc sqlite3.h |
Changes to search/buildsearchdb.tcl.
︙ | ︙ | |||
418 419 420 421 422 423 424 | } } db eval VACUUM } cd doc | | | 418 419 420 421 422 423 424 425 426 | } } db eval VACUUM } cd doc sqlite3 db search.d/search.db rebuild_database |
Changes to search/search.tcl.
︙ | ︙ | |||
107 108 109 110 111 112 113 | #------------------------------------------------------------------------- # Add an entry to the log database for the current query. Which # returns $nRes results. # proc search_add_log_entry {nRes} { if {[info exists ::A(donotlog)]} return | | > | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | #------------------------------------------------------------------------- # Add an entry to the log database for the current query. Which # returns $nRes results. # proc search_add_log_entry {nRes} { if {[info exists ::A(donotlog)]} return sqlite3 db2 search.d/searchlog.db db2 timeout 10000 set ip $::env(REMOTE_ADDR) set query $::A(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 ); |
︙ | ︙ | |||
165 166 167 168 169 170 171 | if {$limit==10} {set s10 selected} if {$limit==100} {set s100 selected} if {$limit==1000} {set s1000 selected} append res " <div style=\"margin:2em\"> <center> | | < | | | 166 167 168 169 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 | if {$limit==10} {set s10 selected} if {$limit==100} {set s100 selected} if {$limit==1000} {set s1000 selected} append res " <div style=\"margin:2em\"> <center> <form action=admin method=get> Results: <select name=limit onChange=\"this.form.submit()\"> <option $s10 value=\"10\">10</option> <option $s100 value=\"100\">100</option> <option $s1000 value=\"1000\">1000</option> </select> IP: <input type=input name=ip value=\"[attrize $ipfilter]\"> Unique: <input type=checkbox name=unique value=1 $checked onChange=\"this.form.submit()\" > <input type=submit> </form> </center> </div> " set i 0 append res "<table border=1 cellpadding=10 align=center>\n" append res "<tr><td><th>IP <th>Query <th> Results <th> Timestamp\n" db2 eval " SELECT rowid, ip, query, nres, timestamp FROM log $where ORDER BY rowid DESC " { if {[info exists ::A(unique)] && $::A(unique)} { if {[info exists seen($query)]} continue set seen($query) 1 } set querylink "<a href=\"../search?q=[attrize $query]&donotlog=1\">$query</a>" set iplink "<a href=\"?admin=1&ip=$ip\">$ip</a>" append res " <tr> <td> $rowid <td> $iplink <td> $querylink" append res " <td> $nres <td> $timestamp\n" incr i if {$i >= $limit} break |
︙ | ︙ | |||
375 376 377 378 379 380 381 | } return $ret } proc main {} { global A | < > > | > > > | 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | } return $ret } proc main {} { global A cgi_parse_args # If "env=1" is specified, dump the environment variables instead # of running any search. if {[info exists ::A(env)]} { return [cgi_env_dump] } # If "admin=1" is specified, jump to the admin screen. if {[string match *admin* $::env(REQUEST_URI)]} { set ::PATH ../ return [admin_list] } sqlite3 db search.d/search.db db transaction { set t [ttime { if {[catch searchresults srchout]} { set A(q) [string tolower $A(q)] set srchout [searchresults] } |
︙ | ︙ | |||
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | set ::HEADER "" #set env(QUERY_STRING) {q="one+two+three+four"+eleven} set env(QUERY_STRING) {q=windows} set ::HEADER "" } if {0==[catch main res]} { set title "Search SQLite Documentation" if {[info exists ::A(q)]} { set initsearch [attrize $::A(q)] append title " - [htmlize $::A(q)]" } else { set initsearch {} } | > | | 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | set ::HEADER "" #set env(QUERY_STRING) {q="one+two+three+four"+eleven} set env(QUERY_STRING) {q=windows} set ::HEADER "" } set ::PATH "" if {0==[catch main res]} { set title "Search SQLite Documentation" if {[info exists ::A(q)]} { set initsearch [attrize $::A(q)] append title " - [htmlize $::A(q)]" } else { set initsearch {} } set document [document_header $title $::PATH $initsearch] append document $res } else { set document "<pre>" append document "Error: $res\n\n" append document $::errorInfo append document "</pre>" } |
︙ | ︙ |