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 ndict2 (
  url_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL
);
CREATE  INDEX n2_url   ON ndict2 (url_id);
CREATE  INDEX n2_word  ON ndict2 (word_id);


CREATE TABLE ndict3 (
  url_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL
);
CREATE  INDEX n3_url   ON ndict3 (url_id);
CREATE  INDEX n3_word  ON ndict3 (word_id);


CREATE TABLE ndict4 (
  url_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL
);
CREATE  INDEX n4_url   ON ndict4 (url_id);
CREATE  INDEX n4_word  ON ndict4 (word_id);


CREATE TABLE ndict5 (
  url_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL
);
CREATE  INDEX n5_url   ON ndict5 (url_id);
CREATE  INDEX n5_word  ON ndict5 (word_id);


CREATE TABLE ndict6 (
  url_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL
);
CREATE  INDEX n6_url   ON ndict6 (url_id);
CREATE  INDEX n6_word  ON ndict6 (word_id);


CREATE TABLE ndict7 (
  url_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL
);
CREATE  INDEX n7_url   ON ndict7 (url_id);
CREATE  INDEX n7_word  ON ndict7 (word_id);


CREATE TABLE ndict8 (
  url_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL
);
CREATE  INDEX n8_url   ON ndict8 (url_id);
CREATE  INDEX n8_word  ON ndict8 (word_id);


CREATE TABLE ndict9 (
  url_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL
);
CREATE  INDEX n9_url   ON ndict9 (url_id);
CREATE  INDEX n9_word  ON ndict9 (word_id);


CREATE TABLE ndict10 (
  url_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL
);
CREATE  INDEX n10_url   ON ndict10 (url_id);
CREATE  INDEX n10_word  ON ndict10 (word_id);


CREATE TABLE ndict11 (
  url_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL
);
CREATE  INDEX n11_url   ON ndict11 (url_id);
CREATE  INDEX n11_word  ON ndict11 (word_id);


CREATE TABLE ndict12 (
  url_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL
);
CREATE  INDEX n12_url   ON ndict12 (url_id);
CREATE  INDEX n12_word  ON ndict12 (word_id);


CREATE TABLE ndict16 (
  url_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL
);
CREATE  INDEX n16_url   ON ndict16 (url_id);
CREATE  INDEX n16_word  ON ndict16 (word_id);


CREATE TABLE ndict32 (
  url_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL
);
CREATE  INDEX n32_url   ON ndict32 (url_id);
CREATE  INDEX n32_word  ON ndict32 (word_id);
