mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-09-29 23:10:52 +00:00
Special: Broadcast events to one specific tab, not all tabs with same name
This commit is contained in:
parent
67548465fc
commit
cc8c120982
@ -18,6 +18,7 @@ import gplx.xowa.langs.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.wikis.pages.dbs.*; import gplx.xowa.wikis.pages.redirects.*; import gplx.xowa.wikis.pages.hdumps.*; import gplx.xowa.wikis.pages.htmls.*; import gplx.xowa.wikis.pages.wtxts.*;
|
||||
public interface Xoa_page {
|
||||
Xow_wiki Wiki();
|
||||
Guid_adp Page_guid();
|
||||
Xoa_url Url(); byte[] Url_bry_safe();
|
||||
Xoa_ttl Ttl();
|
||||
Xopg_db_data Db();
|
||||
|
@ -47,6 +47,13 @@ public class Xoae_page implements Xoa_page {
|
||||
public void Xtn_gallery_packed_exists_y_() {html.Xtn_gallery_packed_exists_y_();}
|
||||
public boolean Xtn__timeline_exists() {return false;} // drd always sets timeline
|
||||
public boolean Xtn__gallery_exists() {return false;} // drd does not need to set gallery.style.css
|
||||
private Guid_adp page_guid;
|
||||
public Guid_adp Page_guid() {
|
||||
if (page_guid == null) {
|
||||
page_guid = Guid_adp_.New();
|
||||
}
|
||||
return page_guid;
|
||||
}
|
||||
|
||||
public Xowe_wiki Wikie() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xol_lang_itm Lang() {return lang;} public Xoae_page Lang_(Xol_lang_itm v) {lang = v; return this;} private Xol_lang_itm lang;
|
||||
|
@ -26,6 +26,7 @@ public class Xofulltext_searcher_args {
|
||||
public byte[] query;
|
||||
public String namespaces;
|
||||
public int query_id;
|
||||
public String page_guid;
|
||||
public static Xofulltext_searcher_args New_by_json(Json_nde args) {
|
||||
Xofulltext_searcher_args rv = new Xofulltext_searcher_args();
|
||||
rv.case_match = args.Get_as_bool_or("case_match", false);
|
||||
@ -37,6 +38,7 @@ public class Xofulltext_searcher_args {
|
||||
rv.wikis = args.Get_as_bry("wikis");
|
||||
rv.query = args.Get_as_bry("query");
|
||||
rv.namespaces = args.Get_as_str("namespaces");
|
||||
rv.page_guid = args.Get_as_str("page_guid");
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
@ -30,9 +30,9 @@ class Xofulltext_highlighter_mgr implements Gfo_invk {
|
||||
private final Gflucene_highlighter_mgr highlighter_mgr = new Gflucene_highlighter_mgr();
|
||||
private final Xoh_page hpg = new Xoh_page();
|
||||
private final Xowd_page_itm tmp_page_row = new Xowd_page_itm();
|
||||
private final List_adp list;
|
||||
private final Ordered_hash list;
|
||||
private final Xofulltext_extractor extractor = new Xofulltext_extractor();
|
||||
public Xofulltext_highlighter_mgr(Xofulltext_searcher_ui ui, Xow_wiki wiki, Xofulltext_searcher_args searcher_args, Gflucene_analyzer_data analyzer_data, Gflucene_searcher_qry searcher_data, List_adp list) {
|
||||
public Xofulltext_highlighter_mgr(Xofulltext_searcher_ui ui, Xow_wiki wiki, Xofulltext_searcher_args searcher_args, Gflucene_analyzer_data analyzer_data, Gflucene_searcher_qry searcher_data, Ordered_hash list) {
|
||||
this.ui = ui;
|
||||
this.wiki = wiki;
|
||||
this.searcher_args = searcher_args;
|
||||
|
@ -24,7 +24,7 @@ public class Xofulltext_searcher__lucene implements Xofulltext_searcher {
|
||||
private final Gflucene_searcher_mgr searcher = new Gflucene_searcher_mgr();
|
||||
public void Search(Xofulltext_searcher_ui ui, Xow_wiki wiki, Xofulltext_searcher_args args) {
|
||||
// create list
|
||||
List_adp list = List_adp_.New();
|
||||
Ordered_hash list = Ordered_hash_.New();
|
||||
|
||||
// init searcher with wiki
|
||||
Gflucene_analyzer_data analyzer_data = Gflucene_analyzer_data.New_data_from_locale(wiki.Lang().Key_str());
|
||||
|
@ -47,7 +47,6 @@ class Xofulltext_searcher_html extends Xow_special_wtr__base {
|
||||
@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());
|
||||
|
@ -29,12 +29,9 @@ import gplx.xowa.addons.wikis.fulltexts.searchers.mgrs.gflucenes.*;
|
||||
import gplx.xowa.addons.wikis.fulltexts.searchers.mgrs.brutes.*;
|
||||
class Xofulltext_searcher_svc implements Gfo_invk {
|
||||
private final Xoa_app app;
|
||||
private final Xog_cbk_trg cbk_trg = Xog_cbk_trg.New(Xofulltext_searcher_special.Prototype.Special__meta().Ttl_bry());
|
||||
private final Xofulltext_cache_mgr cache_mgr = new Xofulltext_cache_mgr();
|
||||
private final Xofulltext_searcher_ui searcher_ui;
|
||||
public Xofulltext_searcher_svc(Xoa_app app) {
|
||||
this.app = app;
|
||||
this.searcher_ui = new Xofulltext_searcher_ui(cache_mgr, app.Gui__cbk_mgr(), cbk_trg);
|
||||
}
|
||||
public void Search(Json_nde args) {
|
||||
// for now, always clear cache; "get_lines_rest" will only work for latest search
|
||||
@ -61,6 +58,8 @@ class Xofulltext_searcher_svc implements Gfo_invk {
|
||||
gplx.core.threads.Thread_adp_.Start_by_val("search", Cancelable_.Never, this, Invk__search, search_args);
|
||||
}
|
||||
private void Search(Xofulltext_searcher_args args) {
|
||||
Xofulltext_searcher_ui searcher_ui = new Xofulltext_searcher_ui(cache_mgr, app.Gui__cbk_mgr(), new Xog_cbk_trg(args.page_guid));
|
||||
|
||||
try {
|
||||
// loop wikis
|
||||
byte[][] wiki_domains = Bry_split_.Split(args.wikis, Byte_ascii.Pipe_bry);
|
||||
@ -79,9 +78,11 @@ class Xofulltext_searcher_svc implements Gfo_invk {
|
||||
}
|
||||
}
|
||||
public void Get_lines_rest(Json_nde args) {
|
||||
Get_lines_rest(args.Get_as_int("qry_id"), args.Get_as_bry("wiki"), args.Get_as_int("page_id"));
|
||||
Get_lines_rest(args.Get_as_int("qry_id"), args.Get_as_bry("wiki"), args.Get_as_int("page_id"), args.Get_as_str("page_guid"));
|
||||
}
|
||||
private void Get_lines_rest(int qry_id, byte[] wiki_bry, int page_id) {
|
||||
private void Get_lines_rest(int qry_id, byte[] wiki_bry, int page_id, String page_guid) {
|
||||
Xofulltext_searcher_ui searcher_ui = new Xofulltext_searcher_ui(cache_mgr, app.Gui__cbk_mgr(), new Xog_cbk_trg(page_guid));
|
||||
|
||||
Xofulltext_cache_line[] lines = cache_mgr.Get_lines_rest(qry_id, wiki_bry, page_id);
|
||||
for (Xofulltext_cache_line line : lines) {
|
||||
searcher_ui.Send_line_add(true, qry_id, wiki_bry, page_id, line.Line_seq(), line.Line_html());
|
||||
|
@ -15,11 +15,19 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.guis.cbks; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
|
||||
public class Xog_cbk_trg {
|
||||
Xog_cbk_trg(byte tid, byte[] page_ttl) {this.tid = tid; this.page_ttl = page_ttl;}
|
||||
public Xog_cbk_trg(byte tid, byte[] page_ttl) {
|
||||
this.tid = tid; this.page_ttl = page_ttl;
|
||||
}
|
||||
public Xog_cbk_trg(String page_guid) {
|
||||
this.tid = Tid__page_guid;
|
||||
this.page_ttl = Bry_.Empty;
|
||||
this.Page_guid = page_guid;
|
||||
}
|
||||
public byte Tid() {return tid;} private final byte tid;
|
||||
public byte[] Page_ttl() {return page_ttl;} private final byte[] page_ttl; // same as ttl.Full_db(); EX: Special:XowaDownloadCentral
|
||||
public String Page_guid;
|
||||
|
||||
public static final byte Tid__cbk_enabled = 0, Tid__specific_page = 1;
|
||||
public static final byte Tid__cbk_enabled = 0, Tid__specific_page = 1, Tid__page_guid = 2;
|
||||
public static final Xog_cbk_trg Any = new Xog_cbk_trg(Tid__cbk_enabled, null);
|
||||
public static Xog_cbk_trg New(byte[] page_ttl) {return new Xog_cbk_trg(Tid__specific_page, page_ttl);}
|
||||
}
|
||||
|
@ -26,8 +26,12 @@ public class Xog_cbk_wkr__swt implements Xog_cbk_wkr {
|
||||
}
|
||||
public Object Send_json(Xog_cbk_trg trg, String func, Gfobj_nde data) {
|
||||
if (gui_mgr.Kit().Tid() != Gfui_kit_.Swt_tid) return null; // guard against calling when HTTP_server
|
||||
|
||||
// create cmd for script
|
||||
String script = json_wtr.Write_as_func__swt(func, data);
|
||||
GfuiInvkCmd swt_cmd = gui_mgr.Kit().New_cmd_sync(browser_func.Script_(script));
|
||||
|
||||
// iterate tabs
|
||||
Xog_tab_mgr tab_mgr = gui_mgr.Browser_win().Tab_mgr();
|
||||
int tabs_len = tab_mgr.Tabs_len();
|
||||
Object rv = null;
|
||||
@ -36,6 +40,9 @@ public class Xog_cbk_wkr__swt implements Xog_cbk_wkr {
|
||||
Xoa_page page = tab.Page();
|
||||
boolean match = false;
|
||||
switch (trg.Tid()) {
|
||||
case Xog_cbk_trg.Tid__page_guid:
|
||||
match = String_.Eq(trg.Page_guid, page.Page_guid().To_str());
|
||||
break;
|
||||
case Xog_cbk_trg.Tid__cbk_enabled:
|
||||
match = page.Html_data().Cbk_enabled();
|
||||
break;
|
||||
|
@ -30,6 +30,13 @@ public class Xoh_page implements Xoa_page {
|
||||
public Xopg_wtxt_data Wtxt() {return wtxt;} private final Xopg_wtxt_data wtxt = new Xopg_wtxt_data();
|
||||
public Xopg_hdump_data Hdump_mgr() {return hdump;} private final Xopg_hdump_data hdump = new Xopg_hdump_data();
|
||||
public Xol_lang_itm Lang() {return lang;} private Xol_lang_itm lang;
|
||||
private Guid_adp page_guid;
|
||||
public Guid_adp Page_guid() {
|
||||
if (page_guid == null) {
|
||||
page_guid = Guid_adp_.New();
|
||||
}
|
||||
return page_guid;
|
||||
}
|
||||
|
||||
public boolean Xtn__timeline_exists() {return xtn__timeline_exists;} private boolean xtn__timeline_exists; public void Xtn__timeline_exists_y_() {xtn__timeline_exists = true;}
|
||||
public boolean Xtn__gallery_exists() {return xtn__gallery_exists;} private boolean xtn__gallery_exists; public void Xtn__gallery_exists_y_() {xtn__gallery_exists = true;}
|
||||
|
@ -28,6 +28,8 @@ public class Xopage_html_data {
|
||||
public Xopg_tag_mgr Tail_tags() {return tail_tags;} private final Xopg_tag_mgr tail_tags = new Xopg_tag_mgr(Bool_.N);
|
||||
|
||||
public void Apply(Xoa_page page) {
|
||||
Xopg_tag_wtr_.Add__tab_uid (head_tags, page.Page_guid());
|
||||
|
||||
Xopg_html_data html_data = page.Html_data();
|
||||
html_data.Html_restricted_n_();
|
||||
html_data.Skip_parse_(Bool_.Y);
|
||||
|
@ -20,6 +20,9 @@ public class Xopg_tag_wtr_ {
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(css_dir.GenSubFil_nest("Namespace_.js")));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(css_dir.GenSubFil_nest("String_.js")));
|
||||
}
|
||||
public static void Add__tab_uid(Xopg_tag_mgr head_tags, Guid_adp page_guid) {
|
||||
head_tags.Add(Xopg_tag_itm.New_js_code("xo.page_guid = '" + page_guid.To_str() + "'"));
|
||||
}
|
||||
public static void Add__xocss(Xopg_tag_mgr head_tags, Io_url http_root) {
|
||||
Io_url css_dir = http_root.GenSubDir_nest("bin", "any", "xowa", "html", "res", "src", "xowa", "xocss", "core");
|
||||
head_tags.Add(Xopg_tag_itm.New_css_file(css_dir.GenSubFil_nest("xocss_core-0.0.1.css")));
|
||||
|
@ -19,6 +19,7 @@ public class Gflucene_index_data {
|
||||
public final Gflucene_analyzer_data analyzer_data;
|
||||
public final String index_dir;
|
||||
public final float max_merged_segments = 1500; // "limits" maximum file size
|
||||
public final boolean positional_enabled = false;
|
||||
public Gflucene_index_data(Gflucene_analyzer_data analyzer_data, String index_dir) {
|
||||
this.analyzer_data = analyzer_data;
|
||||
this.index_dir = index_dir;
|
||||
|
@ -67,10 +67,10 @@ public class Gflucene_indexer_mgr {
|
||||
|
||||
// create field for body
|
||||
this.body_fld_type = new FieldType();
|
||||
body_fld_type.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
|
||||
IndexOptions index_options = idx_data.positional_enabled ? IndexOptions.DOCS_AND_FREQS_AND_POSITIONS : IndexOptions.DOCS_AND_FREQS;
|
||||
body_fld_type.setIndexOptions(index_options);
|
||||
body_fld_type.setTokenized(true);
|
||||
body_fld_type.setStored(false);
|
||||
// body_fld.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
|
||||
// body_fld.setStoreTermVectors(true);
|
||||
// body_fld.setStoreTermVectorOffsets(true);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class Gflucene_searcher_mgr {
|
||||
throw Err_.new_exc(e, "lucene_index", "failed to init searcher", "dir", idx_data.index_dir);
|
||||
}
|
||||
}
|
||||
public void Exec(List_adp list, Gflucene_searcher_qry data) {
|
||||
public void Exec(Ordered_hash list, Gflucene_searcher_qry data) {
|
||||
try {
|
||||
IndexReader reader = DirectoryReader.open(index);
|
||||
IndexSearcher searcher = new IndexSearcher(reader);
|
||||
@ -79,10 +79,14 @@ public class Gflucene_searcher_mgr {
|
||||
int docId = hits[i].doc;
|
||||
Document d = searcher.doc(docId);
|
||||
// Gflucene_doc_data doc = new Gflucene_doc_data(Integer.parseInt(d.get("page_id")), Integer.parseInt(d.get("page_score")), d.get("title"), "");
|
||||
Gflucene_doc_data doc = new Gflucene_doc_data(Integer.parseInt(d.get("page_id")), 0, d.get("title"), "");
|
||||
doc.lucene_score = hits[i].score;
|
||||
String docTitle = d.get("title");
|
||||
Gflucene_doc_data doc = (Gflucene_doc_data)list.Get_by(docTitle);
|
||||
if (doc == null) {
|
||||
doc = new Gflucene_doc_data(Integer.parseInt(d.get("page_id")), 0, docTitle, "");
|
||||
doc.lucene_score = hits[i].score;
|
||||
list.Add(docTitle, doc);
|
||||
}
|
||||
// Tfds.Write(doc.lucene_score, doc.title);
|
||||
list.Add(doc);
|
||||
}
|
||||
|
||||
reader.close();
|
||||
|
Loading…
Reference in New Issue
Block a user