1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.3.4.1'

This commit is contained in:
gnosygnu
2016-03-27 23:44:59 -04:00
parent de67253a9c
commit baaef32df2
903 changed files with 13339 additions and 8695 deletions

View File

@@ -127,8 +127,8 @@ class Xow_data_mgr_fxt {
Xoae_app app;
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public void Clear() {
app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
wiki.Db_mgr().Save_mgr().Page_id_next_(0);
}
public Xow_data_mgr_fxt Create(String ttl_str, String data) {

View File

@@ -17,17 +17,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.bldrs.infos.*;
import gplx.xowa.htmls.core.dbs.*;
import gplx.xowa.wikis.data.site_stats.*;
import gplx.xowa.htmls.core.dbs.*; import gplx.xowa.addons.searchs.dbs.*;
public class Xowd_db_file {
Xowd_db_file(Db_cfg_tbl cfg_tbl, Xob_info_session info_session, Xob_info_file info_file, Xowd_core_db_props props, Xowd_db_file_schema_props schema_props, int id, byte tid, Io_url url, String ns_ids, int part_id, Guid_adp guid, Db_conn conn, byte cmd_mode) {
this.id = id; this.tid = tid; this.url = url; this.ns_ids = ns_ids; this.part_id = part_id; this.guid = guid;
this.id = id; this.tid = tid; this.url = url; this.ns_ids = ns_ids; this.part_id = part_id; this.guid = guid; this.db_props = props; this.schema_props = schema_props;
this.conn = conn; this.cmd_mode = cmd_mode;
this.url_rel = url.NameAndExt();
boolean schema_is_1 = props.Schema_is_1();
this.tbl__cfg = cfg_tbl;
this.tbl__db = new Xowd_xowa_db_tbl(conn, schema_is_1);
this.tbl__ns = new Xowd_site_ns_tbl(conn, schema_is_1);
this.tbl__site_stats = new Xowd_site_stats_tbl(conn, schema_is_1);
this.tbl__site_stats = new Xow_site_stats_tbl(conn, schema_is_1);
this.tbl__page = new Xowd_page_tbl(conn, schema_is_1);
this.tbl__text = new Xowd_text_tbl(conn, schema_is_1, props.Zip_tid_text());
this.tbl__html = new Xoh_page_tbl(conn);
@@ -37,40 +38,39 @@ public class Xowd_db_file {
this.tbl__cat_link = new Xowd_cat_link_tbl(conn, schema_is_1);
this.tbl__wbase_qid = new Xowd_wbase_qid_tbl(conn, schema_is_1, schema_props.Wbase__qid__src_ttl_has_spaces());
this.tbl__wbase_pid = new Xowd_wbase_pid_tbl(conn, schema_is_1);
this.tbl__search_word = new Xowd_search_word_tbl(conn, schema_is_1, schema_props.Search__word__page_count_exists());
this.tbl__search_link = new Xowd_search_link_tbl(conn, schema_is_1);
this.info_session = info_session;
this.info_file = info_file;
}
public int Id() {return id;} private final int id; // unique id in xowa_db
public byte Tid() {return tid;} private final byte tid;
public Io_url Url() {return url;} private final Io_url url;
public String Url_rel() {return url_rel;} private final String url_rel;
public String Ns_ids() {return ns_ids;} private final String ns_ids;
public int Part_id() {return part_id;} private final int part_id;
public Guid_adp Guid() {return guid;} private final Guid_adp guid;
public Db_conn Conn() {return conn;} private final Db_conn conn;
public byte Cmd_mode() {return cmd_mode;} public Xowd_db_file Cmd_mode_(byte v) {cmd_mode = v; return this;} private byte cmd_mode;
public long File_len() {return file_len;} public Xowd_db_file File_len_add(int v) {file_len += v; return this;} private long file_len;
public long File_max() {return file_max;} public Xowd_db_file File_max_(long v) {file_max = v; return this;} private long file_max;
public Xob_info_session Info_session() {return info_session;} private final Xob_info_session info_session;
public Xob_info_file Info_file() {return info_file;} private final Xob_info_file info_file;
public Db_cfg_tbl Tbl__cfg() {return tbl__cfg;} private final Db_cfg_tbl tbl__cfg;
public Xowd_xowa_db_tbl Tbl__db() {return tbl__db;} private final Xowd_xowa_db_tbl tbl__db;
public Xowd_site_ns_tbl Tbl__ns() {return tbl__ns;} private final Xowd_site_ns_tbl tbl__ns;
public Xowd_page_tbl Tbl__page() {return tbl__page;} private final Xowd_page_tbl tbl__page;
public Xowd_text_tbl Tbl__text() {return tbl__text;} private final Xowd_text_tbl tbl__text;
public Xoh_page_tbl Tbl__html() {return tbl__html;} private final Xoh_page_tbl tbl__html;
public Xowd_css_core_tbl Tbl__css_core() {return tbl__css_core;} private final Xowd_css_core_tbl tbl__css_core;
public Xowd_css_file_tbl Tbl__css_file() {return tbl__css_file;} private final Xowd_css_file_tbl tbl__css_file;
public Xowd_cat_core_tbl Tbl__cat_core() {return tbl__cat_core;} private final Xowd_cat_core_tbl tbl__cat_core;
public Xowd_cat_link_tbl Tbl__cat_link() {return tbl__cat_link;} private final Xowd_cat_link_tbl tbl__cat_link;
public Xowd_search_word_tbl Tbl__search_word() {return tbl__search_word;} private final Xowd_search_word_tbl tbl__search_word;
public Xowd_search_link_tbl Tbl__search_link() {return tbl__search_link;} private final Xowd_search_link_tbl tbl__search_link;
public Xowd_site_stats_tbl Tbl__site_stats() {return tbl__site_stats;} private final Xowd_site_stats_tbl tbl__site_stats;
public Xowd_wbase_qid_tbl Tbl__wbase_qid() {return tbl__wbase_qid;} private final Xowd_wbase_qid_tbl tbl__wbase_qid;
public Xowd_wbase_pid_tbl Tbl__wbase_pid() {return tbl__wbase_pid;} private final Xowd_wbase_pid_tbl tbl__wbase_pid;
public void Rls() {conn.Rls_conn();}
public int Id() {return id;} private final int id; // unique id in xowa_db
public byte Tid() {return tid;} private final byte tid;
public Db_conn Conn() {return conn;} private final Db_conn conn;
public Io_url Url() {return url;} private final Io_url url;
public String Url_rel() {return url_rel;} private final String url_rel;
public Xowd_core_db_props Db_props() {return db_props;} private final Xowd_core_db_props db_props;
public Xowd_db_file_schema_props Schema_props() {return schema_props;} private final Xowd_db_file_schema_props schema_props;
public String Ns_ids() {return ns_ids;} private final String ns_ids;
public int Part_id() {return part_id;} private final int part_id;
public Guid_adp Guid() {return guid;} private final Guid_adp guid;
public byte Cmd_mode() {return cmd_mode;} public Xowd_db_file Cmd_mode_(byte v) {cmd_mode = v; return this;} private byte cmd_mode;
public long File_len() {return file_len;} public Xowd_db_file File_len_add(int v) {file_len += v; return this;} private long file_len;
public long File_max() {return file_max;} public Xowd_db_file File_max_(long v) {file_max = v; return this;} private long file_max;
public Xob_info_session Info_session() {return info_session;} private final Xob_info_session info_session;
public Xob_info_file Info_file() {return info_file;} private final Xob_info_file info_file;
public Db_cfg_tbl Tbl__cfg() {return tbl__cfg;} private final Db_cfg_tbl tbl__cfg;
public Xowd_xowa_db_tbl Tbl__db() {return tbl__db;} private final Xowd_xowa_db_tbl tbl__db;
public Xowd_site_ns_tbl Tbl__ns() {return tbl__ns;} private final Xowd_site_ns_tbl tbl__ns;
public Xowd_page_tbl Tbl__page() {return tbl__page;} private Xowd_page_tbl tbl__page;
public Xowd_text_tbl Tbl__text() {return tbl__text;} private final Xowd_text_tbl tbl__text;
public Xoh_page_tbl Tbl__html() {return tbl__html;} private final Xoh_page_tbl tbl__html;
public Xowd_css_core_tbl Tbl__css_core() {return tbl__css_core;} private final Xowd_css_core_tbl tbl__css_core;
public Xowd_css_file_tbl Tbl__css_file() {return tbl__css_file;} private final Xowd_css_file_tbl tbl__css_file;
public Xowd_cat_core_tbl Tbl__cat_core() {return tbl__cat_core;} private final Xowd_cat_core_tbl tbl__cat_core;
public Xowd_cat_link_tbl Tbl__cat_link() {return tbl__cat_link;} private final Xowd_cat_link_tbl tbl__cat_link;
public Xow_site_stats_tbl Tbl__site_stats() {return tbl__site_stats;} private final Xow_site_stats_tbl tbl__site_stats;
public Xowd_wbase_qid_tbl Tbl__wbase_qid() {return tbl__wbase_qid;} private final Xowd_wbase_qid_tbl tbl__wbase_qid;
public Xowd_wbase_pid_tbl Tbl__wbase_pid() {return tbl__wbase_pid;} private final Xowd_wbase_pid_tbl tbl__wbase_pid;
public void Rls() {conn.Rls_conn();}
public Xowd_page_tbl Tbl__page__rebind() {this.tbl__page = new Xowd_page_tbl(tbl__page.conn, tbl__page.schema_is_1); return tbl__page;}
public static final Xowd_db_file Null = null;
public static Xowd_db_file make_(Xob_info_session info_session, Xowd_core_db_props props, int id, byte tid, Io_url url, String ns_ids, int part_id, String core_file_name, Db_conn conn) {

View File

@@ -24,6 +24,7 @@ public class Xowd_db_file_ {
, Tid_wiki_solo = 8, Tid_text_solo = 9
, Tid_html_solo = 10, Tid_html_data = 11
, Tid_file_solo = 12, Tid_file_core = 13, Tid_file_data = 14, Tid_file_user = 15
, Tid_search_link = 16
;
private static final String
Key_core = "core", Key_text = "text", Key_cat = "xtn.category", Key_search_core = "xtn.search.core", Key_wbase = "core.wbase"
@@ -31,6 +32,7 @@ public class Xowd_db_file_ {
, Key_text_solo = "text.solo", Key_wiki_solo = "wiki.solo"
, Key_html_solo = "html.solo", Key_html_data = "html"
, Key_file_solo = "file.solo", Key_file_core = "file.core", Key_file_data = "file.data", Key_file_user = "file.user"
, Key_search_link = "xtn.search.link"
;
public static String To_key(byte v) {
switch (v) {
@@ -49,6 +51,7 @@ public class Xowd_db_file_ {
case Tid_file_core: return Key_file_core;
case Tid_file_data: return Key_file_data;
case Tid_file_user: return Key_file_user;
case Tid_search_link: return Key_search_link;
default: throw Err_.new_unhandled(v);
}
}

View File

@@ -27,6 +27,7 @@ class Xowd_db_file_hash {
tids.Del(file.Id());
--count_total;
}
public Ordered_hash Get_by_tid_or_null(byte tid) {return (Ordered_hash)hash.Get_by(tid);}
public void Add_or_new(Xowd_db_file file) {
byte tid = file.Tid();
Ordered_hash tids = (Ordered_hash)hash.Get_by(tid);

View File

@@ -21,6 +21,7 @@ import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.bldrs.infos.*;
public class Xowd_db_mgr {
private Xowd_db_file[] dbs__ary = new Xowd_db_file[0]; private int dbs__ary_len = 0; private final Xowd_db_file_hash db_file_hash = new Xowd_db_file_hash();
private final Hash_adp id_hash = Hash_adp_.new_(); private final gplx.core.primitives.Int_obj_ref id_hash_ref = gplx.core.primitives.Int_obj_ref.neg1_();
private final Xow_wiki wiki; private final Io_url wiki_root_dir; private final Xow_domain_itm domain_itm;
public Xowd_db_mgr(Xow_wiki wiki, Io_url wiki_root_dir, Xow_domain_itm domain_itm) {this.wiki = wiki; this.wiki_root_dir = wiki_root_dir; this.domain_itm = domain_itm;}
public Xowd_core_db_props Props() {return props;} private Xowd_core_db_props props = Xowd_core_db_props.Test;
@@ -30,18 +31,31 @@ public class Xowd_db_mgr {
public Xowd_db_file Db__text() {return db__text;} private Xowd_db_file db__text;
public Xowd_db_file Db__html() {return db__html;} private Xowd_db_file db__html;
public Xowd_db_file Db__cat_core() {return db__cat_core;} private Xowd_db_file db__cat_core;
public Xowd_db_file Db__search() {return db__search;} private Xowd_db_file db__search;
public Xowd_db_file Db__wbase() {return db__wbase;} private Xowd_db_file db__wbase;
public int Dbs__len() {return dbs__ary.length;}
public void Db__wbase_(Xowd_db_file v) {db__wbase = v;}
public Ordered_hash Dbs__get_hash_by_tid(int tid) {return db_file_hash.Get_by_tid_or_null((byte)tid);}
public Xowd_db_file Dbs__get_at(int i) {return dbs__ary[i];}
public Xowd_db_file Dbs__get_by_id(int id) {return (Xowd_db_file)id_hash.Get_by_or_fail(id_hash_ref.Val_(id));}
public Xowd_db_file Dbs__get_by_tid_or_core(byte... tids_ary) {Xowd_db_file rv = Dbs__get_by_tid_or_null(tids_ary); return rv == null ? db__core : rv;}
public Xowd_db_file Dbs__get_by_tid_or_null(byte... tids_ary) {
int tids_len = tids_ary.length;
for (int i = 0; i < tids_len; ++i) {
byte tid = tids_ary[i];
Ordered_hash tid_dbs = db_file_hash.Get_by_tid_or_null(tid); if (tid_dbs == null) continue;
if (tid_dbs.Len() != 1) throw Err_.new_("xowa.dbs", "expecting only 1 db for tid; tid=~{0} len=~{1} db_api=~{2}", tid, tid_dbs.Len(), db__core.Conn().Conn_info().Db_api());
return (Xowd_db_file)tid_dbs.Get_at(0);
}
return null;
}
public Xowd_db_file Dbs__make_by_tid(byte tid) {
int tid_idx = Get_tid_idx(db_file_hash, tid);
return Dbs__make_by_tid(tid, Xob_info_file.Ns_ids_empty, tid_idx, Get_tid_name(db_file_hash, tid_idx, tid));
}
public Xowd_db_file Dbs__make_by_tid(byte tid, String ns_ids, int part_id, String file_name_suffix) {
Io_url url = wiki_root_dir.GenSubFil(domain_itm.Domain_str() + file_name_suffix);
Xowd_db_file rv = Xowd_db_file.make_(db__core.Info_session(), props, dbs__ary_len, tid, url, ns_ids, part_id, db__core.Url().NameAndExt(), Db_conn_bldr.Instance.New(url));
int next_id = Dbs__get_at(dbs__ary_len - 1).Id() + 1;
Xowd_db_file rv = Xowd_db_file.make_(db__core.Info_session(), props, next_id, tid, url, ns_ids, part_id, db__core.Url().NameAndExt(), Db_conn_bldr.Instance.New(url));
Dbs__add_and_save(rv);
Dbs__set_by_tid(rv);
return rv;
@@ -60,6 +74,7 @@ public class Xowd_db_mgr {
}
public void Init_by_load(Io_url core_url) {
db_file_hash.Clear();
id_hash.Clear();
Db_conn core_conn = Db_conn_bldr.Instance.Get(core_url);
props = Xowd_core_db_props.Cfg_load(core_url, core_conn);
Dbs__set_by_tid(Xowd_db_file.load_(props, Xowd_db_file_.Id_core, Core_db_tid(props.Layout_text()), core_url, Xob_info_file.Ns_ids_empty, Xob_info_file.Part_id_1st, Guid_adp_.Empty));
@@ -69,6 +84,7 @@ public class Xowd_db_mgr {
Xowd_db_file db = dbs__ary[i];
Dbs__set_by_tid(db);
db_file_hash.Add_or_new(db);
id_hash.Add(gplx.core.primitives.Int_obj_ref.new_(db.Id()), db);
}
wiki.Props().Init_by_load(wiki.App(), Tbl__cfg());
}
@@ -100,10 +116,9 @@ public class Xowd_db_mgr {
switch (db.Tid()) {
case Xowd_db_file_.Tid_wiki_solo:
case Xowd_db_file_.Tid_text_solo:
case Xowd_db_file_.Tid_core : {db__core = db; if (props.Layout_text().Tid_is_all_or_few()) db__cat_core = db__search = db__text = db; break;}
case Xowd_db_file_.Tid_core : {db__core = db; if (props.Layout_text().Tid_is_all_or_few()) db__cat_core = db__text = db; break;}
case Xowd_db_file_.Tid_text : {db__text = db; break;}
case Xowd_db_file_.Tid_html_data : {db__html = db; break;}
case Xowd_db_file_.Tid_search_core : {if (db__search == null) db__search = db; break;}
case Xowd_db_file_.Tid_wbase : {if (db__wbase == null) db__wbase = db; break;}
case Xowd_db_file_.Tid_cat_core :
case Xowd_db_file_.Tid_cat : {if (db__cat_core == null) db__cat_core = db; break;}
@@ -116,6 +131,7 @@ public class Xowd_db_mgr {
rv.Info_file().Save(rv.Tbl__cfg());
rv.Info_session().Save(rv.Tbl__cfg());
db_file_hash.Add_or_new(rv);
id_hash.Add(gplx.core.primitives.Int_obj_ref.new_(rv.Id()), rv);
}
public void Rls() {
for (int i = 0; i < dbs__ary_len; i++)

View File

@@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.data.site_stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.xowa.wikis.nss.*;
public class Xow_site_stats_mgr implements GfoInvkAble { // REF.MW:https://www.mediawiki.org/wiki/Manual:Site_stats_table
private final Xow_wiki wiki;
public Xow_site_stats_mgr(Xow_wiki wiki) {this.wiki = wiki;}
public long Num_pages() {return num_pages;} private long num_pages; // ss_total_pages; pages in entire wiki: 16,299,475
public long Num_articles() {return num_articles;} private long num_articles; // ss_good_articles; pages in main ns w/o redirect: 5,072,469
public long Num_views() {return num_views;} private long num_views; // ss_total_views
public long Num_edits() {return num_edits;} private long num_edits; // ss_total_edits
public long Num_users() {return num_users;} private long num_users; // ss_users
public long Num_active() {return num_active;} private long num_active; // ss_active_users
public int Num_admins() {return num_admins;} private int num_admins; // ss_admins
public int Num_files() {return num_files;} private int num_files; // ss_images
public void Load_by_db(long num_pages, long num_articles, int num_files, long num_edits, long num_views, long num_users, long num_active, int num_admins) {
this.num_pages = num_pages;
this.num_articles = num_articles;
this.num_files = num_files;
this.num_edits = num_edits;
this.num_views = num_views;
this.num_users = num_users;
this.num_active = num_active;
this.num_admins = num_admins;
}
private Object Number_of_articles_in_ns_(GfoMsg m) {
int ns_id = m.ReadInt("ns_id");
int count = m.ReadInt("count");
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
if (ns != null) ns.Count_(count);
return this;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_number_of_pages_)) num_pages = m.ReadInt("v");
else if (ctx.Match(k, Invk_number_of_articles_)) num_articles = m.ReadInt("v");
else if (ctx.Match(k, Invk_number_of_files_)) num_files = m.ReadInt("v");
else if (ctx.Match(k, Invk_number_of_articles_in_ns_)) return Number_of_articles_in_ns_(m);
else return GfoInvkAble_.Rv_unhandled;
return this;
} public static final String Invk_number_of_pages_ = "number_of_pages_", Invk_number_of_articles_ = "number_of_articles_", Invk_number_of_files_ = "number_of_files_", Invk_number_of_articles_in_ns_ = "number_of_articles_in_ns_";
}

View File

@@ -15,13 +15,13 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*; import gplx.xowa.wikis.metas.*;
public class Xowd_site_stats_tbl {
package gplx.xowa.wikis.data.site_stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*; import gplx.xowa.wikis.data.site_stats.*;
public class Xow_site_stats_tbl {
private final String tbl_name = "site_stats";
private final String fld_row_id, fld_good_articles, fld_total_pages, fld_images;
private final Db_conn conn; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
public Xowd_site_stats_tbl(Db_conn conn, boolean schema_is_1) {
public Xow_site_stats_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
fld_row_id = flds.Add_int_pkey("ss_row_id");
fld_good_articles = flds.Add_long("ss_good_articles");
@@ -29,7 +29,7 @@ public class Xowd_site_stats_tbl {
fld_images = flds.Add_int("ss_images");
}
public void Create_tbl() {
conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds));
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));
conn.Stmt_insert(tbl_name, flds).Val_int(fld_row_id, Site_stats_row_id).Val_long(fld_good_articles, 0).Val_long(fld_total_pages, 0).Val_int(fld_images, 0).Exec_insert();
}
public void Update(int num_articles, int num_pages, int num_files) {
@@ -38,13 +38,15 @@ public class Xowd_site_stats_tbl {
.Crt_int(fld_row_id, Site_stats_row_id)
.Exec_update();
}
public void Select(Xow_wiki_stats stats) {
public void Select(Xow_site_stats_mgr stats) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_row_id).Crt_int(fld_row_id, Site_stats_row_id).Exec_select__rls_auto();
try {
if (rdr.Move_next()) {
stats.NumArticles_ ((int)rdr.Read_long(fld_good_articles)); // #<>(int)rdr.Read_long~rdr.Read_int
stats.NumPages_ ((int)rdr.Read_long(fld_total_pages)); // #<>(int)rdr.Read_long~rdr.Read_int
stats.NumFiles_ (rdr.Read_int(fld_images));
stats.Load_by_db
( rdr.Read_long(fld_good_articles)
, rdr.Read_long(fld_total_pages)
, rdr.Read_int(fld_images)
, 0, 0, 0, 0, 0);
}
} finally {rdr.Rls();}
}

View File

@@ -37,7 +37,7 @@ public class Xowd_cat_core_tbl implements Rls_able {
in_wkr.Ctor(this, tbl_name, flds, fld_id);
conn.Rls_reg(this);
}
public Xowd_cat_core_tbl Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds)); return this;}
public Xowd_cat_core_tbl Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds)); return this;}
public void Insert_bgn() {conn.Txn_bgn("schema__cat_core__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(int id, int pages, int subcats, int files, byte hidden, int link_db_id) {

View File

@@ -32,9 +32,9 @@ public class Xowd_cat_link_tbl implements Rls_able {
fld_timestamp = flds.Add_str ("cl_timestamp", 14);
conn.Rls_reg(this);
}
public Xowd_cat_link_tbl Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds)); return this;}
public Xowd_cat_link_tbl Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds)); return this;}
public void Create_idx() {
conn.Ddl_create_idx(Xoa_app_.Usr_dlg()
conn.Meta_idx_create(Xoa_app_.Usr_dlg()
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "main", fld_to_id, fld_type_id, fld_sortkey, fld_from)
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "from", fld_from)
);

View File

@@ -29,7 +29,7 @@ public class Xowd_css_core_tbl implements Rls_able {
}
public Db_conn Conn() {return conn;} private final Db_conn conn;
public String Tbl_name() {return tbl_name;}
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "main", fld_key)));}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "main", fld_key)));}
public void Rls() {}
public int Insert(String key, DateAdp updated_on) {
Db_stmt stmt_insert = conn.Stmt_insert(tbl_name, flds);

View File

@@ -31,7 +31,7 @@ public class Xowd_css_file_tbl implements Rls_able {
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
}
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Insert(int css_id, String path, byte[] data) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear().Val_int(fld_css_id, css_id).Val_str(fld_path, path).Val_bry(fld_data, data).Exec_insert();

View File

@@ -33,16 +33,18 @@ public class Xowd_page_itm {
public int Redirect_id() {return redirect_id;} private int redirect_id;
public DateAdp Modified_on() {return modified_on;} public Xowd_page_itm Modified_on_(DateAdp v) {modified_on = v; return this;} private DateAdp modified_on;
public boolean Exists() {return exists;} public Xowd_page_itm Exists_(boolean v) {exists = v; return this;} private boolean exists;
public int Page_score;
public Xow_ns Ns() {return ns;} private Xow_ns ns;
public Object Xtn() {return xtn;} public Xowd_page_itm Xtn_(Object v) {this.xtn = v; return this;} private Object xtn;
public int Tdb_row_idx() {return tdb_row_idx;} public void Tdb_row_idx_(int v) {tdb_row_idx = v;} private int tdb_row_idx;
public int Rank() {return text_len;}
public Xowd_page_itm Init(int id, byte[] ttl_page_db, boolean redirected, int text_len, int text_db_id, int tdb_row_idx) {
this.id = id; this.ttl_page_db = ttl_page_db; this.redirected = redirected;
this.text_len = text_len; this.text_db_id = text_db_id; this.tdb_row_idx = tdb_row_idx;
id_val = null;
return this;
}
public void Init_by_sql(int id, int ns_id, byte[] ttl_page_db, DateAdp modified_on, boolean redirected, int text_len, int text_db_id, int html_db_id, int redirect_id) {
public void Init_by_sql(int id, int ns_id, byte[] ttl_page_db, DateAdp modified_on, boolean redirected, int text_len, int text_db_id, int html_db_id, int redirect_id, int page_score) {
this.id = id;
this.ns_id = ns_id;
this.ttl_page_db = ttl_page_db;
@@ -52,6 +54,7 @@ public class Xowd_page_itm {
this.text_db_id = text_db_id;
this.html_db_id = html_db_id;
this.redirect_id = redirect_id;
this.Page_score = page_score;
}
public void Init_by_tdb(int id, int text_db_id, int tdb_row_idx, boolean redirected, int text_len, int ns_id, byte[] ttl_page_db) {
this.id = id;
@@ -70,7 +73,7 @@ public class Xowd_page_itm {
return this;
}
public Xowd_page_itm Ttl_(Xoa_ttl ttl) {
ttl_full_db = ttl.Full_txt();
ttl_full_db = ttl.Full_txt_w_ttl_case();
ttl_page_db = ttl.Page_db();
ns = ttl.Ns();
ns_id = ns.Id();
@@ -120,9 +123,9 @@ public class Xowd_page_itm {
this.html_db_id = orig.html_db_id;
}
public void Srl_save(Bry_bfr bfr) {gplx.xowa.wikis.tdbs.Xotdb_page_itm_.Txt_id_save(bfr, this);}
public static final int Id_null = -1, Modified_on_null_int = 0;
public static final Xowd_page_itm[] Ary_empty = new Xowd_page_itm[0];
public static final Xowd_page_itm Null = null;
public static final int Id_null = -1, Modified_on_null_int = 0, Redirect_id_null = -1;
public static final Xowd_page_itm[] Ary_empty = new Xowd_page_itm[0];
public static final Xowd_page_itm Null = null;
public static Xowd_page_itm new_tmp() {return new Xowd_page_itm();}
public static Xowd_page_itm new_srch(int id, int text_len) {return new Xowd_page_itm().Id_(id).Text_len_(text_len);}
}

View File

@@ -20,24 +20,26 @@ import gplx.core.primitives.*; import gplx.core.criterias.*;
import gplx.dbs.*; import gplx.xowa.*; import gplx.xowa.wikis.dbs.*; import gplx.dbs.qrys.*;
import gplx.xowa.wikis.nss.*;
public class Xowd_page_tbl implements Rls_able {
private final String tbl_name = "page";
private String fld_id, fld_ns, fld_title, fld_is_redirect, fld_touched, fld_len, fld_random_int, fld_text_db_id, fld_html_db_id, fld_redirect_id;
private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final Db_conn conn; private Db_stmt stmt_select_all_by_ttl, stmt_select_all_by_id, stmt_select_id_by_ttl, stmt_insert; private boolean hdump_enabled;
private final String[] flds_select_all, flds_select_idx;
private final String tbl_name = "page";
private String fld_id, fld_ns, fld_title, fld_is_redirect, fld_touched, fld_len, fld_random_int, fld_score, fld_text_db_id, fld_html_db_id, fld_redirect_id;
private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private Db_stmt stmt_select_all_by_ttl, stmt_select_all_by_id, stmt_select_id_by_ttl, stmt_insert; private boolean hdump_enabled;
private final String[] flds_select_all, flds_select_idx;
public String Tbl_name() {return tbl_name;}
public Dbmeta_fld_list Flds__all() {return flds;}
public String Fld_page_id() {return fld_id;}
public String Fld_page_ns() {return fld_ns;}
public String Fld_page_title() {return fld_title;}
public String Fld_page_len() {return fld_len;}
public String Fld_page_score() {return fld_score;} public static final String Fld__page_score__key = "page_score";
public String Fld_html_db_id() {return fld_html_db_id;}
public String Fld_is_redirect() {return fld_is_redirect;}
public String Fld_redirect_id() {return fld_redirect_id;}
public String[] Flds_select_idx() {return flds_select_idx;}
public String[] Flds_select_all() {return flds_select_all;}
public Db_conn Conn() {return conn;}
public final Db_conn conn; public final boolean schema_is_1;
public Xowd_page_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
this.conn = conn; this.schema_is_1 = schema_is_1;
String fld_text_db_id_name = "";
if (schema_is_1) {fld_text_db_id_name = "page_file_idx";}
else {fld_text_db_id_name = "page_text_db_id";}
@@ -50,11 +52,12 @@ public class Xowd_page_tbl implements Rls_able {
fld_random_int = flds.Add_int("page_random_int"); // MW:XOWA
fld_text_db_id = flds.Add_int(fld_text_db_id_name); // MW:XOWA
Hdump_enabled_(!schema_is_1);
flds_select_all = String_.Ary_wo_null(fld_id, fld_ns, fld_title, fld_touched, fld_is_redirect, fld_len, fld_text_db_id, fld_html_db_id, fld_redirect_id);
flds_select_idx = String_.Ary(fld_ns, fld_title, fld_id, fld_len);
fld_score = Dbmeta_fld_itm.Make_or_null(conn, flds, tbl_name, Dbmeta_fld_tid.Tid__int, -1, Fld__page_score__key);
flds_select_all = String_.Ary_wo_null(fld_id, fld_ns, fld_title, fld_touched, fld_is_redirect, fld_len, fld_text_db_id, fld_html_db_id, fld_redirect_id, fld_score);
flds_select_idx = String_.Ary_wo_null(fld_ns, fld_title, fld_id, fld_len, fld_score);
conn.Rls_reg(this);
}
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds.To_fld_ary()));}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds.To_fld_ary()));}
public void Insert(int page_id, int ns_id, byte[] ttl_wo_ns, boolean page_is_redirect, DateAdp modified_on, int page_len, int random_int, int text_db_id, int html_db_id) {
this.Insert_bgn();
this.Insert_cmd_by_batch(page_id, ns_id, ttl_wo_ns, page_is_redirect, modified_on, page_len, random_int, text_db_id, html_db_id);
@@ -74,6 +77,7 @@ public class Xowd_page_tbl implements Rls_able {
.Val_int(fld_text_db_id, text_db_id)
.Val_int(fld_html_db_id, html_db_id)
.Val_int(fld_redirect_id, -1)
.Val_int(fld_score, -1)
.Exec_insert();
}
public void Hdump_enabled_(boolean v) {
@@ -111,7 +115,7 @@ public class Xowd_page_tbl implements Rls_able {
finally {rdr.Rls();}
return false;
}
public Db_rdr Select_all() {
public Db_rdr Select_all__id__ttl() {
Db_qry__select_cmd qry = new Db_qry__select_cmd().From_(tbl_name).Cols_(fld_id, fld_title).Order_asc_(fld_id);
return conn.Stmt_new(qry).Exec_select__rls_auto();
}
@@ -159,12 +163,11 @@ public class Xowd_page_tbl implements Rls_able {
}
public byte[] Select_random(Xow_ns ns) {// ns should be ns_main
int random_int = RandomAdp_.new_().Next(ns.Count());
Db_rdr rdr = conn.Stmt_select(tbl_name, String_.Ary(fld_title), fld_ns, fld_random_int)
.Crt_int(fld_ns, ns.Id()).Crt_int(fld_random_int, random_int)
Db_rdr rdr = conn.Stmt_select(tbl_name, String_.Ary(fld_title), fld_random_int, fld_ns)
.Crt_int(fld_random_int, random_int).Crt_int(fld_ns, ns.Id())
.Exec_select__rls_auto();
try {
return rdr.Move_next() ? rdr.Read_bry_by_str(fld_title) : null;
} finally {rdr.Rls();}
try {return rdr.Move_next() ? rdr.Read_bry_by_str(fld_title) : null;}
finally {rdr.Rls();}
}
public void Select_by_search(Cancelable cancelable, List_adp rv, byte[] search, int results_max) {
if (Bry_.Len_eq_0(search)) return; // do not allow empty search
@@ -275,16 +278,21 @@ public class Xowd_page_tbl implements Rls_able {
html_db_id = rdr.Read_int(fld_html_db_id);
redirected_id = rdr.Read_int(fld_redirect_id);
}
int page_len = rdr.Read_int(fld_len);
int page_score = page_len;
if (fld_score != Dbmeta_fld_itm.Key_null)
page_score = rdr.Read_int(fld_score);
page.Init_by_sql
( rdr.Read_int(fld_id)
, rdr.Read_int(fld_ns)
, rdr.Read_bry_by_str(fld_title)
, DateAdp_.parse_fmt(rdr.Read_str(fld_touched), Page_touched_fmt)
, rdr.Read_bool_by_byte(fld_is_redirect)
, rdr.Read_int(fld_len)
, page_len
, rdr.Read_int(fld_text_db_id)
, html_db_id
, redirected_id
, page_score
);
}
public void Update__html_db_id(int page_id, int html_db_id) {
@@ -315,24 +323,25 @@ public class Xowd_page_tbl implements Rls_able {
;
}
public void Create_index() {
conn.Ddl_create_idx(Xoa_app_.Usr_dlg()
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "title" , fld_ns, fld_title, fld_id, fld_len, fld_is_redirect)
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "random" , fld_ns, fld_random_int)
conn.Meta_idx_create(Xoa_app_.Usr_dlg()
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "title" , fld_title, fld_ns)
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "random" , fld_random_int)
);
}
public int Fld_page_score_eval(Db_rdr rdr, int page_len) {
return fld_score == Dbmeta_fld_itm.Key_null ? page_len : rdr.Read_int(fld_score);
}
public void Rls() {
stmt_select_all_by_ttl = Db_stmt_.Rls(stmt_select_all_by_ttl);
stmt_select_all_by_id = Db_stmt_.Rls(stmt_select_all_by_id);
stmt_select_id_by_ttl = Db_stmt_.Rls(stmt_select_id_by_ttl);
stmt_insert = Db_stmt_.Rls(stmt_insert);
}
private static final String Page_touched_fmt = "yyyyMMddHHmmss";
private static final String Page_touched_fmt = "yyyyMMddHHmmss";
public static void Assert_col__page_html_db_id(Xowd_db_mgr db_mgr) {
Xowd_page_tbl page_tbl = db_mgr.Tbl__page(); Db_conn page_conn = page_tbl.Conn();
boolean html_flds_exists = page_conn.Meta_fld_exists(page_tbl.Tbl_name(), page_tbl.Fld_html_db_id());
if (html_flds_exists) return;
page_conn.Ddl_append_fld(page_tbl.Tbl_name(), Dbmeta_fld_itm.new_int(page_tbl.Fld_html_db_id()).Default_(-1));
page_conn.Ddl_append_fld(page_tbl.Tbl_name(), Dbmeta_fld_itm.new_int(page_tbl.Fld_redirect_id()).Default_(-1));
Xowd_page_tbl page_tbl = db_mgr.Tbl__page(); Db_conn page_conn = page_tbl.conn;
page_conn.Meta_fld_assert(page_tbl.Tbl_name(), page_tbl.Fld_html_db_id() , Dbmeta_fld_tid.Itm__int, -1);
page_conn.Meta_fld_assert(page_tbl.Tbl_name(), page_tbl.Fld_redirect_id() , Dbmeta_fld_tid.Itm__int, -1);
page_tbl.Hdump_enabled_(Bool_.Y);
}
}

View File

@@ -1,37 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.core.ios.*; import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.wikis.dbs.*; import gplx.dbs.cfgs.*;
public class Xowd_pagelinks_tbl implements Rls_able {
private final String tbl_name = "pagelink"; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_src_id, fld_trg_id;
private final Db_conn conn;
public Xowd_pagelinks_tbl(Db_conn conn) {
this.conn = conn;
fld_src_id = flds.Add_int("src_id");
fld_trg_id = flds.Add_int("trg_id");
flds.Add_int("trg_count");
conn.Rls_reg(this);
}
public Db_conn Conn() {return conn;}
public String Tbl_name() {return tbl_name;}
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Create_idx__src_trg() {conn.Ddl_create_idx(Gfo_usr_dlg_.Instance, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "src_trg", fld_src_id, fld_trg_id));}
public void Create_idx__trg_src() {conn.Ddl_create_idx(Gfo_usr_dlg_.Instance, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "trg_src", fld_trg_id, fld_src_id));}
public void Rls() {}
}

View File

@@ -1,45 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.core.ios.*; import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.wikis.dbs.*; import gplx.dbs.cfgs.*;
public class Xowd_pagelinks_temp_tbl implements Rls_able {
private final String tbl_name = "pagelinks_temp"; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_src_id, fld_trg_ns, fld_trg_ttl;
private final Db_conn conn; private Db_stmt stmt_insert;
public Xowd_pagelinks_temp_tbl(Db_conn conn) {
this.conn = conn;
flds.Add_int_pkey_autonum("uid");
fld_src_id = flds.Add_int("src_id");
fld_trg_ns = flds.Add_int("trg_ns");
fld_trg_ttl = flds.Add_str("trg_ttl", 255);
conn.Rls_reg(this);
}
public Db_conn Conn() {return conn;}
public String Tbl_name() {return tbl_name;}
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Create_idx() {conn.Ddl_create_idx(Gfo_usr_dlg_.Instance, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "main", fld_src_id, fld_trg_ns, fld_trg_ttl));}
public void Insert_bgn() {conn.Txn_bgn("schema__pagelinks__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert(int src_id, int trg_ns, byte[] trg_ttl) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear().Val_int(fld_src_id, src_id).Val_int(fld_trg_ns, trg_ns).Val_bry_as_str(fld_trg_ttl, trg_ttl).Exec_insert();
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
}
}

View File

@@ -1,75 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.core.primitives.*;
import gplx.dbs.*; import gplx.dbs.utls.*;
public class Xowd_search_link_tbl {
private final String tbl_name; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_word_id, fld_page_id;
public final Db_conn conn; private Db_stmt stmt_insert; private final Xowd_search_page_tbl__in_wkr in_wkr = new Xowd_search_page_tbl__in_wkr();
public Xowd_search_link_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
String fld_prefix = "";
if (schema_is_1) {tbl_name = "search_title_page"; fld_prefix = "stp_";}
else {tbl_name = "search_link";}
fld_word_id = flds.Add_int(fld_prefix + "word_id");
fld_page_id = flds.Add_int(fld_prefix + "page_id");
in_wkr.Ctor(tbl_name, flds, fld_page_id, fld_word_id);
}
public String Tbl_name() {return tbl_name;}
public String Fld_word_id() {return fld_word_id;}
public String Fld_page_id() {return fld_page_id;}
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Create_idx_unique() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "main", fld_word_id, fld_page_id));}
public void Create_idx_normal() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "main", fld_word_id, fld_page_id));}
public void Insert_bgn() {conn.Txn_bgn("schema__search_link__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(int word_id, int page_id) {
stmt_insert.Clear().Val_int(fld_word_id, word_id).Val_int(fld_page_id, page_id).Exec_insert();
}
public void Select_in(Cancelable cancelable, List_adp rv, List_adp words) {
in_wkr.Init(words, rv);
in_wkr.Select_in(cancelable, conn, 0, words.Count());
}
}
class Xowd_search_page_tbl__in_wkr extends Db_in_wkr__base {
private String tbl_name; private Dbmeta_fld_list flds; private String fld_page_id, fld_word_id;
private List_adp words, pages;
public void Ctor(String tbl_name, Dbmeta_fld_list flds, String fld_page_id, String fld_word_id) {
this.tbl_name = tbl_name; this.flds = flds; this.fld_page_id = fld_page_id; this.fld_word_id = fld_word_id;
}
public void Init(List_adp words, List_adp pages) {this.words = words; this.pages = pages;}
@Override protected Db_qry Make_qry(int bgn, int end) {
Object[] part_ary = In_ary(end - bgn);
return Db_qry_.select_cols_(tbl_name, Db_crt_.New_in(fld_word_id, part_ary), flds.To_str_ary());
}
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Int_obj_val word_id = (Int_obj_val)words.Get_at(i);
stmt.Crt_int(fld_word_id, word_id.Val());
}
}
@Override protected void Read_data(Cancelable cancelable, Db_rdr rdr) {
while (rdr.Move_next()) {
if (cancelable.Canceled()) return;
int page_id = rdr.Read_int(fld_page_id);
Xowd_page_itm page = new Xowd_page_itm().Id_(page_id);
pages.Add(page);
}
}
}

View File

@@ -1,114 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*;
public class Xowd_search_temp_tbl {
private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_page_id, fld_word_text;
private final Db_conn conn; private Db_stmt stmt_insert;
private final String sql_create_word, sql_create_link;
public Xowd_search_temp_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
if (schema_is_1) {sql_create_word = Sql_create_word_v1; sql_create_link = Sql_create_link_v1;}
else {sql_create_word = Sql_create_word_v2; sql_create_link = Sql_create_link_v2;}
// flds.Add_int_dflt("word_id", -1);
flds.Add_int_pkey_autonum("word_id");
fld_page_id = flds.Add_int("page_id");
fld_word_text = flds.Add_str("word_text", 255);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name = "search_temp";
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Insert_bgn() {conn.Txn_bgn("schema__search_temp__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(int page_id, byte[] word) {
stmt_insert.Clear()
.Val_int(fld_page_id, page_id).Val_bry_as_str(fld_word_text, word)
.Exec_insert();
}
public void Make_data(Gfo_usr_dlg usr_dlg, Xowd_search_link_tbl search_link_tbl, Xowd_search_word_tbl search_word_tbl) {
conn.Ddl_create_idx(usr_dlg, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "main", fld_word_text, fld_page_id));
conn.Exec_delete_all(search_word_tbl.Tbl_name());
conn.Exec_sql_plog_txn("search_temp.create_word", sql_create_word);
conn.Exec_delete_all(search_link_tbl.Tbl_name());
conn.Exec_sql_plog_txn("search_temp.create_link", sql_create_link);
Create_idx(usr_dlg, search_link_tbl, search_word_tbl);
conn.Env_vacuum();
}
public void Create_idx(Gfo_usr_dlg usr_dlg, Xowd_search_link_tbl search_link_tbl, Xowd_search_word_tbl search_word_tbl) {
conn.Ddl_delete_tbl(tbl_name);
try {search_word_tbl.Create_idx();}
catch (Exception e) {usr_dlg.Warn_many("", "", "bldr.search_word.unique_search_failed: err=~{0}", Err_.Message_gplx_full(e));}
try {search_link_tbl.Create_idx_unique();}
catch (Exception e) {
usr_dlg.Warn_many("", "", "bldr.search_page.unique_search_failed: err=~{0}", Err_.Message_gplx_full(e));
search_link_tbl.Create_idx_normal();;
}
}
public void Update_word_id(Db_conn cur_conn, Io_url prv_url) {
String sql = String_.Concat_lines_nl_skip_last
( "REPLACE INTO search_temp (word_id, page_id, word_text)"
, "SELECT Coalesce(prv.word_id, cur.word_id), cur.page_id, cur.word_text"
, "FROM search_temp cur"
, " LEFT JOIN <attach_db>search_word prv ON cur.word_text = prv.word_text"
);
Db_attach_cmd.new_(cur_conn, "prv_db", prv_url).Add_fmt("updating_word_ids", sql).Exec();
Db_stmt update_stmt = cur_conn.Stmt_update(tbl_name, String_.Ary(fld_word_text), fld_page_id);
Db_rdr rdr = cur_conn.Stmt_select(tbl_name, flds, String_.Ary(fld_page_id)).Crt_int(fld_page_id, -1).Exec_select__rls_auto();
int nxt_page_id = 1000;
try {
while (rdr.Move_next()) {
update_stmt.Crt_int(fld_page_id, ++nxt_page_id).Exec_update();
}
} finally {rdr.Rls();}
}
private static final String Sql_create_word_v1 = String_.Concat_lines_nl
( "INSERT INTO search_title_word (stw_word_id, stw_word)"
, "SELECT word_id"
, ", word_text"
, "FROM search_temp"
, "GROUP BY "
, " word_text"
, ";"
);
private static final String Sql_create_link_v1 = String_.Concat_lines_nl
( "INSERT INTO search_title_page (stp_word_id, stp_page_id)"
, "SELECT w.stw_word_id"
, ", t.page_id"
, "FROM search_temp t"
, " JOIN search_title_word w ON t.word_text = w.stw_word"
, ";"
);
private static final String Sql_create_word_v2 = String_.Concat_lines_nl
( "INSERT INTO search_word (word_id, word_text, word_page_count)"
, "SELECT word_id"
, ", word_text"
, ", Count(DISTINCT page_id)"
, "FROM search_temp"
, "GROUP BY "
, " word_text"
, ";"
);
private static final String Sql_create_link_v2 = String_.Concat_lines_nl
( "INSERT INTO search_link (word_id, page_id)"
, "SELECT w.word_id"
, ", t.page_id"
, "FROM search_temp t"
, " JOIN search_word w ON t.word_text = w.word_text"
, ";"
);
}

View File

@@ -1,25 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
public class Xowd_search_word_row {
public Xowd_search_word_row(int id, byte[] text, int page_count) {this.id = id; this.text = text; this.page_count = page_count;}
public int Id() {return id;} private final int id;
public byte[] Text() {return text;} private final byte[] text;
public int Page_count() {return page_count;} private final int page_count;
public static final Xowd_search_word_row Null = null;
}

View File

@@ -1,134 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.core.primitives.*; import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.dbs.qrys.*;
public class Xowd_search_word_tbl implements Rls_able {
private final String tbl_name; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_id, fld_text; private String fld_page_count; private boolean page_count_exists;
public final Db_conn conn; private Db_stmt stmt_insert, stmt_select_by, stmt_select_in;
public Xowd_search_word_tbl(Db_conn conn, boolean schema_is_1, boolean page_count_exists) {
this.conn = conn; this.page_count_exists = page_count_exists;
String fld_prefix = "", fld_text_name = "word_text";
if (schema_is_1) {tbl_name = "search_title_word"; fld_prefix = "stw_"; fld_text_name = "stw_word";}
else {tbl_name = "search_word";}
this.fld_id = flds.Add_int_pkey(fld_prefix + "word_id");
this.fld_text = flds.Add_str(fld_text_name, 255);
this.fld_page_count = page_count_exists ? flds.Add_int_dflt("word_page_count", 0) : Dbmeta_fld_itm.Key_null;
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;}
public String Fld_id() {return fld_id;}
public String Fld_text() {return fld_text;}
public String Fld_page_count() {return fld_page_count;}
public String Fld_page_score_max() {return Dbmeta_fld_itm.Key_null;}
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Create_idx() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "main", fld_text, fld_id, fld_page_count));}
public void Insert_bgn() {conn.Txn_bgn("schema__search_word__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(int id, byte[] word, int page_count) {
stmt_insert.Clear().Val_int(fld_id, id).Val_bry_as_str(fld_text, word).Val_int(fld_page_count, page_count).Exec_insert();
}
public Xowd_search_word_row Select_by_or_null(byte[] word) {
if (stmt_select_by == null) stmt_select_by = conn.Stmt_select(tbl_name, flds, fld_text);
Db_rdr rdr = stmt_select_by.Clear().Crt_bry_as_str(fld_text, word).Exec_select__rls_manual();
try {
return rdr.Move_next() ? new_row(rdr) : Xowd_search_word_row.Null;
}
finally {rdr.Rls();}
}
private Xowd_search_word_row new_row(Db_rdr rdr) {
int page_count = fld_page_count == Dbmeta_fld_itm.Key_null ? 0 : rdr.Read_int(fld_page_count);
return new Xowd_search_word_row(rdr.Read_int(fld_id), rdr.Read_bry_by_str(fld_text), page_count);
}
public Xowd_search_word_row[] Select_in(Cancelable cxl, byte[] word) {
if (stmt_select_in == null) {
Db_qry__select_cmd qry = Db_qry_.select_().From_(tbl_name).Order_(fld_page_count, Bool_.N).Where_(Db_crt_.New_like(fld_text, "")); // order by highest page count to look at most common words
stmt_select_in = conn.Stmt_new(qry);
}
List_adp list = List_adp_.new_();
Db_rdr rdr = stmt_select_in.Clear().Crt_bry_as_str(fld_text, Bry_.Replace(word, Byte_ascii.Star, Byte_ascii.Percent)).Exec_select__rls_manual();
try {
int row_count = 0;
while (rdr.Move_next()) {
if (cxl.Canceled()) break;
Xowd_search_word_row word_row = new_row(rdr);
if (++row_count % 10 == 0)
Xoa_app_.Usr_dlg().Prog_many("", "", "search; reading pages for word: word=~{0} pages=~{1}", word_row.Text(), word_row.Page_count());
list.Add(word_row);
}
}
finally {rdr.Rls();}
return (Xowd_search_word_row[])list.To_ary_and_clear(Xowd_search_word_row.class);
}
public void Select_by_word(Cancelable cancelable, Xowd_search_link_tbl search_page_tbl, List_adp rv, byte[] search, int results_max) {
gplx.core.criterias.Criteria crt = null;
if (Bry_.Has(search, Byte_ascii.Star)) {
search = Bry_.Replace(search, Byte_ascii.Star, Byte_ascii.Percent);
crt = Db_crt_.New_like (fld_text, String_.new_u8(search));
}
else
crt = Db_crt_.New_eq (fld_text, String_.new_u8(search));
Db_qry__select_cmd qry = Db_qry_.select_().Cols_(fld_id).From_(tbl_name).Where_(crt);
List_adp words = List_adp_.new_();
Db_rdr rdr = conn.Stmt_new(qry).Crt_bry_as_str(fld_text, search).Exec_select__rls_auto();
try {
while (rdr.Move_next())
words.Add(Int_obj_val.new_(rdr.Read_int(fld_id)));
}
finally {rdr.Rls();}
search_page_tbl.Select_in(cancelable, rv, words);
}
public boolean Ddl__page_count() {return page_count_exists;}
public void Ddl__page_count_y_() { // needed for search_cmd;
page_count_exists = true;
if (!flds.Has("word_page_count"))
flds.Add_int_dflt("word_page_count", 0);
}
public void Ddl__page_count__add(Xowd_search_link_tbl link_tbl, Db_cfg_tbl cfg_tbl) {
Dbmeta_fld_itm page_count_fld = Dbmeta_fld_itm.new_int("word_page_count").Default_(0);
conn.Txn_bgn("schema__search_word__upgrade");
conn.Ddl_append_fld(tbl_name, page_count_fld); // SQL: ALTER TABLE search_word ADD word_page_count integer NOT NULL DEFAULT 0;
String sql = String_.Format(String_.Concat_lines_nl_skip_last
( "REPLACE INTO {0} ({1}, {2}, word_page_count)"
, "SELECT w.{1}"
, ", w.{2}"
, ", Count(l.{4})"
, "FROM {0} w"
, " JOIN {3} l ON w.{1} = l.{4}"
, "GROUP BY w.{1}"
, ", w.{2};"
), tbl_name, fld_id, fld_text
, link_tbl.Tbl_name(), link_tbl.Fld_word_id()
);
conn.Exec_sql_plog_ntx("calculating page count per word (please wait)", sql);
Ddl__page_count__cfg(cfg_tbl);
fld_page_count = page_count_fld.Name(); flds.Add(page_count_fld); this.Rls();
conn.Txn_end();
}
public void Ddl__page_count__cfg(Db_cfg_tbl cfg_tbl) {
cfg_tbl.Insert_yn(Xowd_db_file_schema_props.Grp, Xowd_db_file_schema_props.Key__col_search_word_page_count, Bool_.Y);
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_select_by = Db_stmt_.Rls(stmt_select_by);
stmt_select_in = Db_stmt_.Rls(stmt_select_in);
}
public static final int Id_null = -1;
}

View File

@@ -31,7 +31,7 @@ public class Xowd_site_ns_tbl {
fld_is_alias = flds.Add_bool ("ns_is_alias");
fld_count = flds.Add_int ("ns_count");
}
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Insert(Xow_ns_mgr ns_mgr) {
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds);
int len = ns_mgr.Ids_len();

View File

@@ -31,7 +31,7 @@ public class Xowd_text_tbl implements Rls_able {
fld_text_data = flds.Add_bry(fld_text_data_name);
conn.Rls_reg(this);
}
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Insert_bgn() {conn.Txn_bgn("schema__text__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(int page_id, byte[] text_data) {

View File

@@ -31,8 +31,8 @@ public class Xowd_wbase_pid_tbl implements Rls_able {
fld_trg_ttl = flds.Add_str(fld_prefix + "trg_ttl", 512);
conn.Rls_reg(this);
}
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Create_idx() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "src", fld_src_lang, fld_src_ttl));}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Create_idx() {conn.Meta_idx_create(Xoa_app_.Usr_dlg(), Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "src", fld_src_lang, fld_src_ttl));}
public void Insert_bgn() {conn.Txn_bgn("schema__wbase_pid__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(byte[] src_lang, byte[] src_ttl, byte[] trg_ttl) {

View File

@@ -33,8 +33,8 @@ public class Xowd_wbase_qid_tbl implements Rls_able {
fld_trg_ttl = flds.Add_str(fld_prefix + "trg_ttl", 512);
conn.Rls_reg(this);
}
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Create_idx() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "src", fld_src_wiki, fld_src_ns, fld_src_ttl));}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Create_idx() {conn.Meta_idx_create(Xoa_app_.Usr_dlg(), Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "src", fld_src_wiki, fld_src_ns, fld_src_ttl));}
public void Insert_bgn() {conn.Txn_bgn("schema__wbase_qid__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(byte[] src_wiki, int src_ns, byte[] src_ttl, byte[] trg_ttl) {

View File

@@ -38,7 +38,7 @@ public class Xowd_xowa_db_tbl {
}
stmt_bldr.Conn_(conn, tbl_name, flds, fld_id);
}
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public Xowd_db_file[] Select_all(Xowd_core_db_props props, Io_url wiki_root_dir) {
List_adp list = List_adp_.new_();
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();