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:
@@ -18,15 +18,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.drds; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.drds.pages.*; import gplx.xowa.drds.files.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.files.gui.*;
|
||||
import gplx.xowa.specials.search.*; import gplx.xowa.specials.randoms.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.files.gui.*;
|
||||
import gplx.xowa.addons.searchs.searchers.rslts.*; import gplx.xowa.specials.randoms.*;
|
||||
import gplx.langs.htmls.encoders.*; import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.addons.searchs.*; import gplx.xowa.addons.searchs.searchers.*;
|
||||
import gplx.xowa.langs.cases.*;
|
||||
public class Xod_app {
|
||||
private final Xoav_app app;
|
||||
private final Xod_page_mgr page_mgr = new Xod_page_mgr();
|
||||
private final Xod_file_mgr file_mgr = new Xod_file_mgr();
|
||||
private final Xoav_app app;
|
||||
private final Xod_page_mgr page_mgr = new Xod_page_mgr();
|
||||
private final Xod_file_mgr file_mgr = new Xod_file_mgr();
|
||||
private final Srch_ns_mgr ns_mgr = new Srch_ns_mgr();
|
||||
public Xod_app(Xoav_app app) {
|
||||
this.app = app;
|
||||
ns_mgr.Add_main_if_empty();
|
||||
}
|
||||
public Xow_wiki Wikis__get_by_domain(String wiki_domain) {
|
||||
Xow_wiki rv = app.Wiki_mgri().Get_by_or_make_init_y(Bry_.new_u8(wiki_domain));
|
||||
@@ -41,19 +45,10 @@ public class Xod_app {
|
||||
Xoa_url url = wiki.Utl__url_parser().Parse(random_ttl_bry);
|
||||
return Wiki__get_by_url(wiki, url);
|
||||
}
|
||||
// public String[] Wiki__search(Cancelable cancelable, Srch_rslt_lnr rslt_lnr, Xow_wiki wiki, String search) {
|
||||
// Srch_db_wkr search_wkr = new Srch_db_wkr();
|
||||
// Srch_rslt_itm[] rows = search_wkr.Search_by_drd(cancelable, wiki, ui_async, Bry_.new_u8(search), 50);
|
||||
// int len = rows.length;
|
||||
// String[] rv = new String[len];
|
||||
// for (int i = 0; i < len; ++i) {
|
||||
// rv[i] = String_.new_u8(rows[i].page_ttl.Page_txt());
|
||||
// }
|
||||
// return rv;
|
||||
// }
|
||||
public void Wiki__search(Cancelable cancelable, Srch_rslt_lnr rslt_lnr, Xow_wiki wiki, String search, Xod_search_cmd[] cmds) {
|
||||
for (Xod_search_cmd cmd : cmds)
|
||||
cmd.Search(cancelable, rslt_lnr, wiki, search);
|
||||
public void Wiki__search(Cancelable cxl, Srch_rslt_cbk cbk, Xow_wiki wiki, String search, int bgn, int end) {
|
||||
Srch_search_addon addon = Get_addon(wiki);
|
||||
Srch_search_qry qry = Srch_search_qry.New__drd(wiki, ns_mgr, Bry_.new_u8(search), bgn, end);
|
||||
addon.Search(qry, cbk);
|
||||
}
|
||||
public void Page__load_files(Xow_wiki wiki, Xod_page_itm pg, Xog_js_wkr js_wkr) {
|
||||
file_mgr.Load_files(wiki, pg, js_wkr);
|
||||
@@ -67,4 +62,5 @@ public class Xod_app {
|
||||
page_bry = Xoa_ttl.Replace_spaces(page_bry); // convert spaces to unders; canonical-url has spaces
|
||||
return page_bry;
|
||||
}
|
||||
private Srch_search_addon Get_addon(Xow_wiki wiki) {return Srch_search_addon.Get(wiki);}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class Xod_app_tstr {
|
||||
this.app = Xoa_app_fxt.Make__app__view();
|
||||
this.wiki = Xoa_app_fxt.Make__wiki__view(app);
|
||||
data_mgr.Wiki_(wiki);
|
||||
Xoa_test_.Init__db__mem(wiki);
|
||||
Xoa_test_.Init__db__view(wiki);
|
||||
drd_provider = new Xod_app(app);
|
||||
}
|
||||
public Xowd_data_tstr Data_mgr() {return data_mgr;} private final Xowd_data_tstr data_mgr = new Xowd_data_tstr();
|
||||
|
||||
@@ -1,22 +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.drds; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.specials.search.*;
|
||||
public interface Xod_search_cmd {
|
||||
void Search(Cancelable cancelable, Srch_rslt_lnr rslt_lnr, Xow_wiki wiki, String search);
|
||||
}
|
||||
@@ -1,74 +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.drds; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.specials.search.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xod_search_cmd_ {
|
||||
public static final Xod_search_cmd
|
||||
New__page_eq = Xod_search_cmd__page_eq.Instance
|
||||
, New__page_like = Xod_search_cmd__page_like.Instance
|
||||
, New__word_eq = Xod_search_cmd__word_tbl.Instance_eq
|
||||
, New__word_like = Xod_search_cmd__word_tbl.Instance_like
|
||||
;
|
||||
}
|
||||
class Xod_search_cmd__page_eq implements Xod_search_cmd {
|
||||
public void Search(Cancelable cancelable, Srch_rslt_lnr rslt_lnr, Xow_wiki wiki, String search) {
|
||||
Xowd_page_itm page_itm = new Xowd_page_itm();
|
||||
if (wiki.Data__core_mgr().Tbl__page().Select_by_ttl(page_itm, wiki.Ns_mgr().Ns_main(), Bry_.Ucase__1st(Bry_.new_u8(search)))) {
|
||||
Srch_rslt_itm search_itm = new Srch_rslt_itm(wiki.Domain_bry(), wiki.Ttl_parse(page_itm.Ttl_page_db()), page_itm.Id(), page_itm.Text_len());
|
||||
rslt_lnr.Notify_rslt_found(search_itm);
|
||||
}
|
||||
}
|
||||
public static final Xod_search_cmd__page_eq Instance = new Xod_search_cmd__page_eq(); Xod_search_cmd__page_eq() {}
|
||||
}
|
||||
class Xod_search_cmd__page_like implements Xod_search_cmd {// NOTE: slow; takes at least 10+ seconds
|
||||
public void Search(Cancelable cancelable, Srch_rslt_lnr rslt_lnr, Xow_wiki wiki, String search) {
|
||||
List_adp tmp_list = List_adp_.new_();
|
||||
wiki.Data__core_mgr().Tbl__page().Select_by_search(cancelable, tmp_list, Bry_.Ucase__1st(Bry_.new_u8(search + "*")), 50);
|
||||
int len = tmp_list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xowd_page_itm page_itm = (Xowd_page_itm)tmp_list.Get_at(i);
|
||||
Srch_rslt_itm search_itm = new Srch_rslt_itm(wiki.Domain_bry(), wiki.Ttl_parse(page_itm.Ttl_page_db()), page_itm.Id(), page_itm.Text_len());
|
||||
rslt_lnr.Notify_rslt_found(search_itm);
|
||||
}
|
||||
}
|
||||
public static final Xod_search_cmd__page_like Instance = new Xod_search_cmd__page_like(); Xod_search_cmd__page_like() {}
|
||||
}
|
||||
class Xod_search_cmd__word_tbl implements Xod_search_cmd {
|
||||
private final boolean wildcard;
|
||||
private final int results_wanted;
|
||||
private final Srch_db_wkr search_wkr = new Srch_db_wkr();
|
||||
Xod_search_cmd__word_tbl(boolean wildcard, int results_wanted) {this.wildcard = wildcard; this.results_wanted = results_wanted;}
|
||||
public void Search(Cancelable cancelable, Srch_rslt_lnr rslt_lnr, Xow_wiki wiki, String search) {
|
||||
search_wkr.Search_by_drd(cancelable, rslt_lnr, wiki, Bry_.new_u8(Standardize_search(search, wildcard)), results_wanted);
|
||||
}
|
||||
public static final Xod_search_cmd__word_tbl Instance_eq = new Xod_search_cmd__word_tbl(Bool_.N, 10), Instance_like = new Xod_search_cmd__word_tbl(Bool_.Y, 50);
|
||||
private static String Standardize_search(String search, boolean wildcard) {
|
||||
String rv = "";
|
||||
String[] words = String_.Split(search, " ");
|
||||
int words_len = words.length;
|
||||
for (int i = 0; i < words_len; ++i) {
|
||||
String word = words[i];
|
||||
if (String_.Len(word) < 3) continue;
|
||||
if (String_.Len(rv) != 0) rv += " ";
|
||||
rv += word;
|
||||
if (wildcard) rv += "*";
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user