# This is script for MySQL to 
# create database structure for UdmSearch 3.2.x
# use: "mysql database <create.txt"
#


#DROP TABLE url;
#DROP TABLE urlinfo;
#DROP TABLE robots;
#DROP TABLE dict;
#DROP TABLE ndict;
#DROP TABLE crossdict;
#DROP TABLE ncrossdict;
#DROP TABLE categories;
#DROP TABLE qtrack;
#DROP TABLE server;
#DROP TABLE links;


CREATE TABLE url (
  rec_id	  int(11) DEFAULT '0' NOT NULL auto_increment,
  status	  smallint(6) DEFAULT '0' NOT NULL,
  docsize	  int(11) DEFAULT '0' NOT NULL,
  next_index_time INT NOT NULL,
  last_mod_time	  INT NOT NULL,
  referrer	  int(11) DEFAULT '0' NOT NULL,
  hops		  smallint(6) DEFAULT '0' NOT NULL,
  crc32		  int(11)	DEFAULT '0' NOT NULL,
  seed		  smallint(6) DEFAULT '0' NOT NULL,
  bad_since_time  INT NOT NULL,
  site_id	  int(11),
  pop_rank	  float DEFAULT 0 NOT NULL,
  url		  char(128) binary DEFAULT '' NOT NULL,
  PRIMARY KEY (rec_id),
  UNIQUE url (url),
  KEY key_crc (crc32),
  KEY key_seed (seed),
  KEY key_referrer (referrer),
  KEY key_bad_since_time (bad_since_time),
  KEY key_next_index_time (next_index_time)
);

CREATE TABLE urlinfo (
  url_id INT         NOT NULL,
  sname  VARCHAR(32) NOT NULL,
  sval   TEXT        NOT NULL,
  KEY    urlinfo_id  (url_id)
);


CREATE TABLE dict (
  url_id int(11) DEFAULT '0' NOT NULL,
  word varchar(32) DEFAULT '' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL,
  KEY url_id (url_id),
  KEY word_url (word)
);


CREATE TABLE robots (
  hostinfo varchar(127) DEFAULT '' NOT NULL,
  path varchar(127) DEFAULT '' NOT NULL
);


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



CREATE TABLE qtrack (
  qwords  varchar(63) DEFAULT '' NOT NULL,
  ip      varchar(16) DEFAULT '' NOT NULL,
  qtime   int(11) DEFAULT '0' NOT NULL,
  found   int(11) DEFAULT '0' NOT NULL,
  ps int(11) DEFAULT '' NOT NULL,
  np int(11) DEFAULT '' NOT NULL,
  m varchar(63) DEFAULT '' NOT NULL,
  wm varchar(63) DEFAULT '' NOT NULL,
  o int(11) DEFAULT '' NOT NULL,
  t varchar(63) DEFAULT '' NOT NULL,
  cat varchar(63) DEFAULT '' NOT NULL,
  ul varchar(63) DEFAULT '' NOT NULL,
  wf varchar(63) DEFAULT '' NOT NULL,
  g varchar(63) DEFAULT '' NOT NULL,
  tmplt varchar(63) DEFAULT '' NOT NULL,
  groupbysite char(1) DEFAULT 'N' NOT NULL,
  site_id int(11) DEFAULT '0' NOT NULL
);



CREATE TABLE crossdict (
  url_id int(11) DEFAULT '0' NOT NULL,
  ref_id int(11) DEFAULT '0' NOT NULL,
  word  varchar (32) DEFAULT '0' NOT NULL,
  intag  int(11) DEFAULT '0' NOT NULL,
  KEY url_id (url_id),
  KEY ref_id (ref_id),
  KEY word (word)
);


CREATE TABLE ncrossdict (
  url_id int(11) DEFAULT '0' NOT NULL,
  ref_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag  int(11) DEFAULT '0' NOT NULL,
  KEY url_id (url_id),
  KEY ref_id (ref_id),
  KEY word_id (word_id)
);


CREATE TABLE ndict (
  url_id int(11) DEFAULT '0' NOT NULL,
  word_id int(11) DEFAULT '0' NOT NULL,
  intag int(11) DEFAULT '0' NOT NULL,
  KEY url_id (url_id),
  KEY word_id (word_id)
);

create table server (
	rec_id		int not null auto_increment primary key,
	active		int		not null	default 0,
	url		varchar(128)	not null	default '',
	alias		varchar(128)	not null	default '',
	period		int		not null	default 604800,
	tag		varchar(16)	not null	default '',
	category	varchar(16)	not null	default '',
	charset		varchar(40)	not null	default '',
	lang		varchar(32)	not null	default '',
	basic_auth	varchar(64)	not null	default '',
	proxy		varchar(64)	not null	default '',
	proxy_auth	varchar(64)	not null	default '',

	maxhops		int		not null	default 9999,
	gindex		int		not null	default 1,
	follow		int		not null	default 1,
	use_robots	int		not null	default 1,
	use_clones	int		not null	default 1,
	max_net_errors	int		not null	default 16,
	net_delay_time	int		not null	default 86400,
	read_timeout	int		not null	default 90,

	command		char(1)		not null	default 'S',
	match_type	int				default 17,
	ordre		int		not null	default 0,
	parent		int		not null	default 0,
	weight		int		not null	default 1,
	pop_weight	float		not null	default 0,
	KEY srv_ordre (ordre),
	KEY srv_parent (parent),
	KEY srv_command (command)
);

CREATE UNIQUE INDEX srv_url ON server (url);

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