Skip to content

Commit

Permalink
Make some changes in the database schema:
Browse files Browse the repository at this point in the history
1. Add columns for storing md5 checksum and machine architecture in
 the mandb table.
2. Update the DBSCHEMA file to reflect these changes and also remove
the UNIQUE constraint from the link column in mandb_links table,
which was wrong.
3. Add code in makemandb.c to store these two columns in mandb.
4. Give a weight of 0.0 to the md5_hash column in the ranking algorithm
as it should not affect the search results and weight of 1.0 to the
machine column.
Fixes #64
  • Loading branch information
abhinav-upadhyay committed Jan 6, 2012
1 parent 526f96d commit 2dd48dc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
7 changes: 5 additions & 2 deletions DBSCHEMA
Expand Up @@ -15,9 +15,12 @@ There are three tables in the database at present:
6. return_vals RETURN VALUES section 6. return_vals RETURN VALUES section
7. env ENVIRONMENT section 7. env ENVIRONMENT section
8. files FILES section 8. files FILES section
9. exit_status EXIT STATUS section 9. exit_status EXIT STATUS section
10. diagnostics DIAGNOSTICS section 10. diagnostics DIAGNOSTICS section
11. errors ERRORS section 11. errors ERRORS section
12. md5_hash md5 hash of the man page
13. machine The machine architecture (if any) for which this page is
relevant.


(2) mandb_meta: (2) mandb_meta:
This table contains md5 hashes of all the indexed man This table contains md5 hashes of all the indexed man
Expand All @@ -42,7 +45,7 @@ There are three tables in the database at present:
from the multiple .Nm entries in the page. from the multiple .Nm entries in the page.


Column Name Description Column Name Description
1. link The name of the hard/soft link (UNIQUE index) 1. link The name of the hard/soft link (index)
2. target Name of the target page to which it points 2. target Name of the target page to which it points
3. section The section number 3. section The section number
4. machine The machine architecture (if any) for which 4. machine The machine architecture (if any) for which
Expand Down
13 changes: 8 additions & 5 deletions apropos-utils.c
Expand Up @@ -66,7 +66,9 @@ static const double col_weights[] = {
0.01, //FILES 0.01, //FILES
0.001, //EXIT STATUS 0.001, //EXIT STATUS
2.00, //DIAGNOSTICS 2.00, //DIAGNOSTICS
0.05 //ERRORS 0.05, //ERRORS
0.00, //md5_hash
1.00 //machine
}; };


/* /*
Expand Down Expand Up @@ -144,10 +146,11 @@ create_db(sqlite3 *db)


sqlstr = "CREATE VIRTUAL TABLE mandb USING fts4(section, name, " sqlstr = "CREATE VIRTUAL TABLE mandb USING fts4(section, name, "
"name_desc, desc, lib, return_vals, env, files, " "name_desc, desc, lib, return_vals, env, files, "
"exit_status, diagnostics, errors, compress=zip, " "exit_status, diagnostics, errors, md5_hash, machine, "
"uncompress=unzip, tokenize=porter); " //mandb table "tokenize=porter); " //mandb
"CREATE TABLE IF NOT EXISTS mandb_meta(device, inode, mtime, file UNIQUE, " "CREATE TABLE IF NOT EXISTS mandb_meta(device, inode, mtime, "
"md5_hash UNIQUE, id INTEGER PRIMARY KEY); " //mandb_meta "file UNIQUE, md5_hash UNIQUE, id INTEGER PRIMARY KEY); "
//mandb_meta
"CREATE TABLE IF NOT EXISTS mandb_links(link, target, section, " "CREATE TABLE IF NOT EXISTS mandb_links(link, target, section, "
"machine); "; //mandb_links "machine); "; //mandb_links


Expand Down
20 changes: 19 additions & 1 deletion makemandb.c
Expand Up @@ -1353,7 +1353,7 @@ insert_into_db(sqlite3 *db, mandb_rec *rec)
/*------------------------ Populate the mandb table---------------------------*/ /*------------------------ Populate the mandb table---------------------------*/
sqlstr = "INSERT INTO mandb VALUES (:section, :name, :name_desc, :desc, " sqlstr = "INSERT INTO mandb VALUES (:section, :name, :name_desc, :desc, "
":lib, :return_vals, :env, :files, :exit_status, " ":lib, :return_vals, :env, :files, :exit_status, "
":diagnostics, :errors)"; ":diagnostics, :errors, :md5_hash, :machine)";


rc = sqlite3_prepare_v2(db, sqlstr, -1, &stmt, NULL); rc = sqlite3_prepare_v2(db, sqlstr, -1, &stmt, NULL);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
Expand Down Expand Up @@ -1460,6 +1460,24 @@ insert_into_db(sqlite3 *db, mandb_rec *rec)
cleanup(rec); cleanup(rec);
return -1; return -1;
} }

idx = sqlite3_bind_parameter_index(stmt, ":md5_hash");
rc = sqlite3_bind_text(stmt, idx, rec->md5_hash, -1, NULL);
if (rc != SQLITE_OK) {
warnx("%s", sqlite3_errmsg(db));
sqlite3_finalize(stmt);
cleanup(rec);
return -1;
}

idx = sqlite3_bind_parameter_index(stmt, ":machine");
rc = sqlite3_bind_text(stmt, idx, rec->machine, -1, NULL);
if (rc != SQLITE_OK) {
warnx("%s", sqlite3_errmsg(db));
sqlite3_finalize(stmt);
cleanup(rec);
return -1;
}


rc = sqlite3_step(stmt); rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) { if (rc != SQLITE_DONE) {
Expand Down

0 comments on commit 2dd48dc

Please sign in to comment.