CREATE TABLE dict (
       word                 VARCHAR2(32) NOT NULL,
       url_id               NUMBER(12) NOT NULL,
       intag                NUMBER(12) NOT NULL
)
       PCTFREE 5
       PCTUSED 95
;

CREATE INDEX dict_word   ON dict (word);
CREATE INDEX dict_url_id ON dict (url_id);


CREATE TABLE url (
       rec_id               NUMBER(12) NOT NULL,
       status               NUMBER(6) DEFAULT 0 NOT NULL,
       docsize              NUMBER(12) DEFAULT 0 NOT NULL,
       next_index_time      NUMBER(12) NULL,
       last_mod_time        NUMBER(12) DEFAULT 0 NOT NULL,
       since                NUMBER(12) DEFAULT 0 NOT NULL,
       referrer             NUMBER(12) DEFAULT 0 NOT NULL,
       hops                 NUMBER(6) DEFAULT 0 NOT NULL,
       crc32                NUMBER(12) DEFAULT -1 NOT NULL,
       seed                 NUMBER(6) DEFAULT 0 NOT NULL,
       bad_since_time       NUMBER(12) NULL,
       site_id		    NUMBER(12),
       server_id	    NUMBER(12),
       charset_id           NUMBER(6),
       shows                NUMBER(4) DEFAULT 0 NOT NULL,
       pop_rank	  	    FLOAT DEFAULT 0.0 NOT NULL,
       url                  VARCHAR2(128) NOT NULL
)
       PCTFREE 5
       PCTUSED 95
;

CREATE UNIQUE INDEX url_url ON url (url ASC);
CREATE INDEX url_rec_id ON url (rec_id);
CREATE INDEX url_crc32 ON url (crc32 ASC);
CREATE INDEX url_next_index_time_ind ON url (next_index_time);
CREATE INDEX url_poprank ON url (pop_rank);

CREATE SEQUENCE next_url_id INCREMENT BY 1 START WITH 1;


CREATE TABLE urlinfo (
       url_id NUMBER(38) NOT NULL,
       sname  VARCHAR2(64) NOT NULL,
       sval   VARCHAR2(1024)
);

CREATE INDEX urlinfo_id_ind ON urlinfo (url_id);


CREATE TABLE server (
	rec_id          NUMBER          DEFAULT 0   NOT NULL, 
	enabled		NUMBER		DEFAULT 0   NOT NULL,
	url		VARCHAR2(128)	DEFAULT ''  NOT NULL,
	period		NUMBER		DEFAULT 604800 NOT NULL,
	tag		VARCHAR2(16)	DEFAULT '',
	category	VARCHAR2(16)	DEFAULT ''  NOT NULL,
	command		CHAR(1)		DEFAULT 'S' NOT NULL,
	ordre		NUMBER		DEFAULT 0   NOT NULL,
	parent		NUMBER		DEFAULT 0   not null,
	weight		float		DEFAULT 1   not null,
	pop_weight	float		DEFAULT 0   not null
);

CREATE SEQUENCE server_rec_id_seq INCREMENT BY 1 START WITH 1;

ALTER TABLE server ADD CONSTRAINT server_pk PRIMARY KEY (rec_id);
CREATE UNIQUE INDEX srv_url ON server (url); 
CREATE INDEX srv_ordre ON server (ordre);
CREATE INDEX srv_parent ON server (parent);
CREATE INDEX srv_command ON server (command);


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


	     
CREATE TABLE links (
	ot	 NUMBER not null,
	k	 NUMBER not null,
	weight   FLOAT DEFAULT 0.0 not null,
	valid    CHAR(1) DEFAULT 't' not null
);

CREATE UNIQUE INDEX links_links ON links (ot, k);
CREATE INDEX links_ot ON links (ot);
CREATE INDEX links_k ON links (k);

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

CREATE INDEX cat_path ON categories (path);
CREATE INDEX cat_link ON categories (link);

CREATE TABLE "qtrack" (
        rec_id int NOT NULL PRIMARY KEY,
	ip     char(16) NOT NULL,
	qwords varchar(1024) NOT NULL,
	qtime  int NOT NULL,
	wtime  int NOT NULL,
	found  int NOT NULL
);
CREATE INDEX qtrack_ipt ON qtrack(ip,qtime);

CREATE TABLE "qinfo" (
       q_id  int,
       name  varchar(96),
       value varchar(1024)
);
CREATE INDEX qinfo_id ON qinfo (q_id);
CREATE INDEX qinfo_nv ON qinfo (name, value);


CREATE TABLE robots (
       cmd 	    int,
       added_time   int,
       ordre	    int,
       hostinfo	    varchar(255),
       path	    text
);
CREATE UNIQUE INDEX robots_idx ON robots (hostinfo, ordre);
CREATE INDEX robots_time ON robots (added_time);


CREATE TABLE storedchk (
       rec_id int, 
       url_id int
       );
CREATE INDEX storedchk_i ON storedchk (url_id);

