PRAGMA default_synchronous=OFF;

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,
  since 	  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,
  charset_id      smallint,
  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 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 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 INDEX key_cat_path ON categories (path);
CREATE INDEX key_cat_link ON categories (link);


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,
  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 ncrossdict (
  url_id  int DEFAULT 0 NOT NULL,
  ref_id  int DEFAULT 0 NOT NULL,
  word_id int DEFAULT 0 NOT NULL,
  intag   int DEFAULT 0 NOT NULL
);
CREATE INDEX key_ncrossdict_url_id  ON ncrossdict (url_id);
CREATE INDEX key_ncrossdict_ref_id  ON ncrossdict (ref_id);
CREATE INDEX key_ncrossdict_word_id ON ncrossdict (word_id);


CREATE TABLE ndict (
  url_id  int DEFAULT 0 NOT NULL,
  word_id int DEFAULT 0 NOT NULL,
  intag   int DEFAULT 0 NOT NULL
);
CREATE INDEX key_ndict_url_id ON ndict (url_id);
CREATE INDEX key_ndict_word   ON ndict (word_id);


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 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,
       valid       char(1) not null default 't'
);

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 storedchk (
       rec_id int, 
       url_id int
);
CREATE INDEX storedchk_i ON storedchk (url_id);

CREATE TABLE dict2 (
  url_id int        NOT NULL,
  word char(2)      NOT NULL,
  intag int         NOT NULL
);

CREATE TABLE dict3 (
  url_id int        NOT NULL,
  word char(3)      NOT NULL,
  intag int         NOT NULL
);


CREATE TABLE dict4 (
  url_id int        NOT NULL,
  word char(4)      NOT NULL,
  intag int         NOT NULL
);

CREATE TABLE dict5 (
  url_id int        NOT NULL,
  word char(5)      NOT NULL,
  intag int         NOT NULL
);


CREATE TABLE dict6 (
  url_id int        NOT NULL,
  word char(6)      NOT NULL,
  intag int         NOT NULL
);


CREATE TABLE dict7 (
  url_id int        NOT NULL,
  word char(7)      NOT NULL,
  intag int         NOT NULL
);


CREATE TABLE dict8 (
  url_id int        NOT NULL,
  word char(8)      NOT NULL,
  intag int         NOT NULL
);


CREATE TABLE dict9 (
  url_id int        NOT NULL,
  word char(9)      NOT NULL,
  intag int         NOT NULL
);


CREATE TABLE dict10 (
  url_id int        NOT NULL,
  word char(10)     NOT NULL,
  intag int         NOT NULL
);


CREATE TABLE dict11 (
  url_id int        NOT NULL,
  word char(11)     NOT NULL,
  intag int         NOT NULL
);



CREATE TABLE dict12 (
  url_id int        NOT NULL,
  word char(12)     NOT NULL,
  intag int         NOT NULL
);



CREATE TABLE dict16 (
  url_id int        NOT NULL,
  word char(16)     NOT NULL,
  intag int         NOT NULL
);


CREATE TABLE dict32 (
  url_id int        NOT NULL,
  word varchar(32)  NOT NULL,
  intag int         NOT NULL
);



CREATE  INDEX url_id2 ON dict2 (url_id);
CREATE  INDEX word2   ON dict2 (word);

CREATE  INDEX url_id3 ON dict3 (url_id);
CREATE  INDEX word3   ON dict3 (word);

CREATE  INDEX url_id4 ON dict4 (url_id);
CREATE  INDEX word4   ON dict4 (word);

CREATE  INDEX url_id5 ON dict5 (url_id);
CREATE  INDEX word5   ON dict5 (word);

CREATE  INDEX url_id6 ON dict6 (url_id);
CREATE  INDEX word6   ON dict6 (word);

CREATE  INDEX url_id7 ON dict7 (url_id);
CREATE  INDEX word7   ON dict7 (word);

CREATE  INDEX url_id8 ON dict8 (url_id);
CREATE  INDEX word8   ON dict8 (word);

CREATE  INDEX url_id9 ON dict9 (url_id);
CREATE  INDEX word9   ON dict9 (word);

CREATE  INDEX url_id10 ON dict10 (url_id);
CREATE  INDEX word10   ON dict10 (word);

CREATE  INDEX url_id11 ON dict11 (url_id);
CREATE  INDEX word11   ON dict11 (word);

CREATE  INDEX url_id12 ON dict12 (url_id);
CREATE  INDEX word12   ON dict12 (word);

CREATE  INDEX url_id16 ON dict16 (url_id);
CREATE  INDEX word16   ON dict16 (word);

CREATE  INDEX url_id32 ON dict32 (url_id);
CREATE  INDEX word32   ON dict32 (word);

