Search: Add special page for full-text search

pull/620/head
gnosygnu 8 years ago
parent 27951c428d
commit 1feb2b9877

@ -71,6 +71,7 @@ public class Xoax_addon_mgr {
, new gplx.xowa.addons.apps.cfgs .Xoa_cfg_addon()
, new gplx.xowa.addons.apps.updates .Xoa_update_addon()
, new gplx.xowa.addons.apps.maints.sql_execs .Xosql_exec_addon()
, new gplx.xowa.addons.wikis.searchs.fulltexts .Xosearch_fulltext_addon()
// jsons
);

@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.searchs.fulltexts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*;
import gplx.xowa.specials.*; import gplx.xowa.htmls.bridges.*;
public class Xosearch_fulltext_addon implements Xoax_addon_itm, Xoax_addon_itm__special, Xoax_addon_itm__json {
public Xow_special_page[] Special_pages() {
return new Xow_special_page[]
{ gplx.xowa.addons.wikis.searchs.fulltexts.specials.Xosearch_fulltext_special.Prototype
};
}
public Bridge_cmd_itm[] Json_cmds() {
return new Bridge_cmd_itm[]
{ gplx.xowa.addons.wikis.searchs.fulltexts.cbks.Xosearch_fulltext_bridge.Prototype
};
}
public String Addon__key() {return ADDON__KEY;} private static final String ADDON__KEY = "xowa.wiki.fulltext";
}

@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.searchs.fulltexts.cbks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.fulltexts.*;
import gplx.langs.jsons.*;
import gplx.xowa.htmls.bridges.*;
public class Xosearch_fulltext_bridge implements Bridge_cmd_itm {
private Xosearch_fulltext_svc svc;
public void Init_by_app(Xoa_app app) {
this.svc = new Xosearch_fulltext_svc(app);
}
public String Exec(Json_nde data) {
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Bridge_cmd_mgr.Msg__proc, null), Byte_ascii.Max_7_bit);
Json_nde args = data.Get_kv(Bridge_cmd_mgr.Msg__args).Val_as_nde();
switch (proc_id) {
case Proc__search: svc.Search(args); break;
default: throw Err_.new_unhandled_default(proc_id);
}
return "";
}
private static final byte Proc__search = 0;
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()
.Add_str_byte("search" , Proc__search)
;
public byte[] Key() {return BRIDGE_KEY;} public static final byte[] BRIDGE_KEY = Bry_.new_a7("xowa.wiki.search.fulltext");
public static final Xosearch_fulltext_bridge Prototype = new Xosearch_fulltext_bridge(); Xosearch_fulltext_bridge() {}
}

@ -0,0 +1,58 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.searchs.fulltexts.cbks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.fulltexts.*;
import gplx.langs.jsons.*;
import gplx.dbs.*; import gplx.xowa.specials.xowa.diags.*;
import gplx.xowa.addons.wikis.searchs.fulltexts.specials.*;
import gplx.xowa.wikis.data.tbls.*;
class Xosearch_fulltext_svc {
private gplx.xowa.guis.cbks.Xog_cbk_trg cbk_trg = gplx.xowa.guis.cbks.Xog_cbk_trg.New(Xosearch_fulltext_special.Prototype.Special__meta().Ttl_bry());
private final Xoa_app app;
public Xosearch_fulltext_svc(Xoa_app app) {
this.app = app;
}
public void Search(Json_nde args) {
String wikis = args.Get_as_str("wikis");
byte[] wildcard = Bry_.new_a7("%");
byte[] query = Bry_.Add(wildcard, args.Get_as_bry("query"), wildcard);
String[] wikis_ary = String_.Split(wikis, "|");
for (String wiki_domain : wikis_ary) {
Xow_wiki wiki = app.Wiki_mgri().Get_by_or_make_init_y(Bry_.new_u8(wiki_domain));
Search_wiki(wiki, query);
}
}
private void Search_wiki(Xow_wiki wiki, byte[] query) {
app.Gui__cbk_mgr().Send_json(cbk_trg, "xo.search_fulltext.results__wiki__add__recv", gplx.core.gfobjs.Gfobj_nde.New()
.Add_bry("wiki", wiki.Domain_bry())
.Add_long("page_count", wiki.Stats().Num_pages())
);
Xowd_text_row[] text_rows = wiki.Data__core_mgr().Db__text().Tbl__text().Select_where(query);
for (Xowd_text_row text_row : text_rows) {
app.Gui__cbk_mgr().Send_json(cbk_trg, "xo.search_fulltext.results__page__add__recv", gplx.core.gfobjs.Gfobj_nde.New()
.Add_bry("wiki", wiki.Domain_bry())
.Add_int("page", text_row.page_id)
.Add_int("lines", text_row.text.length)
);
}
}
}
// class Xosearch_result_wiki {
// public final byte[] wiki;
// public final byte[] page_db;
// public byte
// }

@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.searchs.fulltexts.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.fulltexts.*;
import gplx.langs.mustaches.*;
public class Xosearch_fulltext_doc implements Mustache_doc_itm {
public Xosearch_fulltext_doc() {
}
public boolean Mustache__write(String key, Mustache_bfr bfr) {
// if (String_.Eq(key, "domain")) bfr.Add_str_u8(domain);
// else return false;
return true;
}
public Mustache_doc_itm[] Mustache__subs(String key) {
return Mustache_doc_itm_.Ary__empty;
}
}

@ -0,0 +1,45 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.searchs.fulltexts.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.fulltexts.*;
import gplx.xowa.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
import gplx.dbs.*;
class Xosearch_fulltext_html extends Xow_special_wtr__base {
public Xosearch_fulltext_html() {
}
@Override protected Io_url Get_addon_dir(Xoa_app app) {return Addon_dir(app);}
@Override protected Io_url Get_mustache_fil(Io_url addon_dir) {return addon_dir.GenSubFil_nest("bin", "xosearch_fulltext.template.html");}
@Override protected Mustache_doc_itm Bld_mustache_root(Xoa_app app) {
return new Xosearch_fulltext_doc();
}
@Override protected void Bld_tags(Xoa_app app, Io_url addon_dir, Xopage_html_data page_data) {
Xopg_tag_mgr head_tags = page_data.Head_tags();
Xopg_tag_wtr_.Add__xoelem (head_tags, app.Fsys_mgr().Http_root());
Xopg_tag_wtr_.Add__xocss (head_tags, app.Fsys_mgr().Http_root());
Xopg_tag_wtr_.Add__xohelp (head_tags, app.Fsys_mgr().Http_root());
Xopg_tag_wtr_.Add__xolog (head_tags, app.Fsys_mgr().Http_root());
Xopg_tag_wtr_.Add__xoajax (head_tags, app.Fsys_mgr().Http_root(), app);
Xopg_tag_wtr_.Add__jquery (head_tags, app.Fsys_mgr().Http_root());
Xopg_tag_wtr_.Add__xonotify (head_tags, app.Fsys_mgr().Http_root());
Xopg_alertify_.Add_tags (head_tags, app.Fsys_mgr().Http_root());
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xosearch_fulltext.css")));
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("bin", "xosearch_fulltext.js")));
}
public static Io_url Addon_dir(Xoa_app app) {
return app.Fsys_mgr().Http_root().GenSubDir_nest("bin", "any", "xowa", "addon", "wiki", "search", "fulltext");
}
}

@ -0,0 +1,32 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.searchs.fulltexts.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.fulltexts.*;
import gplx.xowa.specials.*; import gplx.core.net.qargs.*;
public class Xosearch_fulltext_special implements Xow_special_page {
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
Gfo_qarg_mgr url_args = new Gfo_qarg_mgr().Init(url.Qargs_ary());
// String domain = url_args.Read_str_or("domain", "[xowa.home]");
// String db = url_args.Read_str_or("db", "core");
// String sql = url_args.Read_str_or("sql", "SELECT * FROM xowa_cfg;");
new Xosearch_fulltext_html().Bld_page_by_mustache(wiki.App(), page, this);
}
Xosearch_fulltext_special(Xow_special_meta special__meta) {this.special__meta = special__meta;}
public Xow_special_meta Special__meta() {return special__meta;} private final Xow_special_meta special__meta;
public Xow_special_page Special__clone() {return this;}
public static final Xow_special_page Prototype = new Xosearch_fulltext_special(Xow_special_meta.New_xo("XowaSearch", "Search"));
}

@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
public class Xowd_text_row {
public final int page_id;
public final byte[] text;
public Xowd_text_row(int page_id, byte[] text) {
this.page_id = page_id;
this.text = text;
}
}

@ -67,6 +67,20 @@ public class Xowd_text_tbl implements Db_tbl {
} finally {rdr.Rls();}
}
}
public Xowd_text_row[] Select_where(byte[] query) {
List_adp list = List_adp_.New();
Db_rdr rdr = conn.Stmt_sql(Db_sql_.Make_by_fmt(String_.Ary("SELECT * FROM text WHERE text_data LIKE '{0}'") , query)).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
int page_id = rdr.Read_int(fld_page_id);
byte[] text = rdr.Read_bry(fld_text_data);
if (text == null) text = Bry_.Empty; // NOTE: defect wherein blank page inserts null not ""; for now always convert null to empty String; DATE:2015-11-08
text = zip_mgr.Unzip(zip_tid, text);
list.Add(new Xowd_text_row(page_id, text));
}
} finally {rdr.Rls();}
return (Xowd_text_row[])list.To_ary_and_clear(Xowd_text_row.class);
}
public byte[] Zip(byte[] data) {return zip_mgr.Zip(zip_tid, data);}
public void Rls() {
synchronized (thread_lock) { // LOCK:stmt-rls; DATE:2016-07-06

Loading…
Cancel
Save