PRAGMA default_synchronous=OFF;

BEGIN TRANSACTION;
CREATE TABLE url (
  rec_id	  INTEGER  NOT NULL PRIMARY KEY,
  status	  smallint DEFAULT 0  NOT NULL,
  docsize	  int      DEFAULT 0  NOT NULL,
  next_index_time INT      DEFAULT 0  NOT NULL,
  last_mod_time	  INT      DEFAULT 0  NOT NULL,
  referrer	  int      DEFAULT 0  NOT NULL,
  hops		  smallint DEFAULT 0  NOT NULL,
  crc32		  int	   DEFAULT -1 NOT NULL,
  seed		  smallint DEFAULT 0  NOT NULL,
  bad_since_time  INT      DEFAULT 0  NOT NULL,
  site_id	  int,
  server_id	  int,
  shows           int      DEFAULT 0  NOT NULL,
  pop_rank	  float    DEFAULT 0  NOT NULL,
  url		  BLOB     DEFAULT '' NOT NULL
);

CREATE UNIQUE INDEX key_url_url      ON url (url);
CREATE INDEX key_url_crc             ON url (crc32);
CREATE INDEX key_url_seed            ON url (seed);
CREATE INDEX key_url_referrer        ON url (referrer);
CREATE INDEX key_url_bad_since_time  ON url (bad_since_time);
CREATE INDEX key_url_next_index_time ON url (next_index_time);
CREATE INDEX key_url_site_id         ON url (site_id);
CREATE INDEX key_url_hops            ON url (hops);
CREATE INDEX key_url_status          ON url (status);
CREATE INDEX key_url_server_id       ON url (server_id);

CREATE TABLE urlinfo (
  url_id INT NOT NULL,
  sname  VARCHAR(32)  NOT NULL,
  sval   TEXT         NOT NULL
);
CREATE INDEX key_urlinfo_url_id ON urlinfo (url_id);


CREATE TABLE dict (
  url_id int    DEFAULT 0  NOT NULL,
  word varchar  DEFAULT '' NOT NULL,
  intag int     DEFAULT 0  NOT NULL
);
CREATE INDEX key_dict_url_id ON dict (url_id);
CREATE INDEX key_dict_word   ON dict (word);

CREATE TABLE bdict (
	word VARCHAR(255) NOT NULL,
	secno INTEGER NOT NULL,
	intag BLOB NOT NULL
);
CREATE INDEX key_bdict_word ON bdict (word);

CREATE TABLE qcache (
  id      INT NOT NULL,
  tm      INT NOT NULL,
  doclist BLOB NOT NULL,
  wordinfo TEXT NOT NULL,
  PRIMARY KEY (id,tm)
);
CREATE INDEX key_qcache_tmstamp ON qcache(tm);


CREATE TABLE categories (
  rec_id INTEGER             NOT NULL PRIMARY KEY,
  path   char(10) DEFAULT '' NOT NULL,
  link   char(10) DEFAULT '' NOT NULL,
  name   char(64) DEFAULT '' NOT NULL
);


CREATE TABLE qtrack (
  rec_id  INTEGER                 NOT NULL PRIMARY KEY,
  ip      varchar(16)  DEFAULT '' NOT NULL,
  qwords  TEXT         DEFAULT '' NOT NULL,
  qtime   int          DEFAULT 0  NOT NULL,
  wtime   int          DEFAULT 0  NOT NULL,
  found   int          DEFAULT 0  NOT NULL
);
CREATE INDEX key_qtrack_ipt ON qtrack(ip,qtime);


CREATE TABLE qinfo (
       q_id  int,
       name  varchar(128),
       value varchar(255)
);
CREATE INDEX key_qinfo_id ON qinfo (q_id);


CREATE TABLE crossdict (
  url_id int         DEFAULT 0  NOT NULL,
  ref_id int         DEFAULT 0  NOT NULL,
  word   varchar(32) DEFAULT '' NOT NULL,
  intag  int         DEFAULT 0  NOT NULL
);
CREATE INDEX key_crossdict_url_id ON crossdict (url_id);
CREATE INDEX key_crossdict_ref_id ON crossdict (ref_id);
CREATE INDEX key_crossdict_word   ON crossdict (word);

create table server (
	rec_id		INTEGER		not null primary key,
	enabled		int		not null	default 0,
	url		BLOB		not null	default '',
	tag		TEXT		not null	default '',
	category	int		not null	default 0,
	command		char(1)		not null	default 'S',
	ordre		int		not null	default 0,
	parent		int		not null	default 0,
	weight		float		not null	default 1,
	pop_weight	float		not null	default 0
);
CREATE INDEX key_server_ordre      ON server (ordre);
CREATE INDEX key_server_parent     ON server (parent);
CREATE INDEX key_server_command    ON server (command);
CREATE INDEX key_server_tag        ON SERVER (tag);
CREATE INDEX key_server_category   ON SERVER (category);
CREATE UNIQUE INDEX key_server_url ON server (url);


CREATE TABLE srvinfo (
       srv_id int  NOT NULL,
       sname  text NOT NULL,
       sval   text NOT NULL
);
CREATE INDEX srvinfo_id ON srvinfo (srv_id);


create table links (
       ot	   int   not null default 0,
       k	   int   not null default 0,
       weight	   float not null default 0
);

CREATE UNIQUE INDEX key_links_links ON links (ot, k);
CREATE        INDEX key_links_ot    ON links (ot);
CREATE        INDEX key_links_k     ON links (k);

CREATE TABLE wrdstat (
  word varchar(64) NOT NULL,
  snd varchar(64) NOT NULL,
  cnt int NOT NULL
);
CREATE INDEX wrdstat_word ON wrdstat (word);
CREATE INDEX wrdstat_snd  ON wrdstat (snd);
COMMIT;
CREATE TABLE bdicti (
  url_id INT NOT NULL,
  state TINYINT NOT NULL,
  intag00 BLOB NOT NULL, intag01 BLOB NOT NULL,
  intag02 BLOB NOT NULL, intag03 BLOB NOT NULL,
  intag04 BLOB NOT NULL, intag05 BLOB NOT NULL,
  intag06 BLOB NOT NULL, intag07 BLOB NOT NULL,
  intag08 BLOB NOT NULL, intag09 BLOB NOT NULL,
  intag0A BLOB NOT NULL, intag0B BLOB NOT NULL,
  intag0C BLOB NOT NULL, intag0D BLOB NOT NULL,
  intag0E BLOB NOT NULL, intag0F BLOB NOT NULL,
  intag10 BLOB NOT NULL, intag11 BLOB NOT NULL,
  intag12 BLOB NOT NULL, intag13 BLOB NOT NULL,
  intag14 BLOB NOT NULL, intag15 BLOB NOT NULL,
  intag16 BLOB NOT NULL, intag17 BLOB NOT NULL,
  intag18 BLOB NOT NULL, intag19 BLOB NOT NULL,
  intag1A BLOB NOT NULL, intag1B BLOB NOT NULL,
  intag1C BLOB NOT NULL, intag1D BLOB NOT NULL,
  intag1E BLOB NOT NULL, intag1F BLOB NOT NULL
);
CREATE INDEX bdicti_url_id ON bdicti (url_id);
CREATE INDEX bdicti_state ON bdicti (state);
