1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00

Full-text search: Allow multiple-wiki specificity for expand_snips

This commit is contained in:
gnosygnu 2017-03-27 12:42:30 -04:00
parent f8f8fa3c3b
commit 968e8917c2
7 changed files with 31 additions and 45 deletions

View File

@ -20,12 +20,10 @@ public class Xofulltext_args_qry {
public int qry_id;
public String page_guid;
public byte[] search_text;
public boolean expand_options;
public Xofulltext_cache_mgr cache_mgr;
public Xofulltext_args_wiki[] wikis_ary;
public boolean expand_snips;
public boolean show_all_snips;
public boolean expand_options;
public boolean case_match;
public boolean auto_wildcard_bgn;
public boolean auto_wildcard_end;
@ -44,6 +42,8 @@ public class Xofulltext_args_qry {
public static Xofulltext_args_qry New_by_json(Json_nde args) {
Xofulltext_args_qry rv = new Xofulltext_args_qry();
rv.search_text = args.Get_as_bry("search");
rv.page_guid = args.Get_as_str("page_guid");
rv.expand_options = args.Get_as_bool_or("expand_options", false);
// create wikis
byte[] wikis_bry = args.Get_as_bry("qarg_wikis");
@ -57,11 +57,8 @@ public class Xofulltext_args_qry {
Set_prop(wiki_args, wikis_len, args, "ns_ids");
Set_prop(wiki_args, wikis_len, args, "offsets");
Set_prop(wiki_args, wikis_len, args, "limits");
rv.page_guid = args.Get_as_str("page_guid");
rv.expand_snips = args.Get_as_bool_or("expand_snips", false);
rv.show_all_snips = args.Get_as_bool_or("show_all_snips", false);
rv.expand_options = args.Get_as_bool_or("expand_options", false);
Set_prop(wiki_args, wikis_len, args, "expand_snips");
Set_prop(wiki_args, wikis_len, args, "show_all_snips");
rv.case_match = args.Get_as_bool_or("case_match", false);
rv.auto_wildcard_bgn = args.Get_as_bool_or("auto_wildcard_bgn", false);
@ -74,7 +71,7 @@ public class Xofulltext_args_qry {
byte[][] ary = Bry_split_.Split(json_val, Byte_ascii.Pipe, true);
int ary_len = ary.length;
for (int i = 0; i < wikis_len; i++) {
byte[] val = i < ary_len ? ary[i] : ary[0];
byte[] val = i < ary_len ? ary[i] : ary[ary_len - 1];
wikis[i].Init_by_json(key, val);
}
}

View File

@ -21,6 +21,8 @@ public class Xofulltext_args_wiki {
public int bgn;
public int len;
public int end() {return bgn + len;}
public boolean expand_snips;
public boolean show_all_snips;
public Xofulltext_args_wiki(byte[] wiki) {
this.wiki = wiki;
@ -36,5 +38,7 @@ public class Xofulltext_args_wiki {
}
else if (String_.Eq(key, "offsets")) this.bgn = Bry_.To_int(val);
else if (String_.Eq(key, "limits")) this.len = Bry_.To_int(val);
else if (String_.Eq(key, "expand_snips")) this.expand_snips = Bry_.Eq(val, Bool_.Y_bry);
else if (String_.Eq(key, "show_all_snips")) this.show_all_snips = Bry_.Eq(val, Bool_.Y_bry);
}
}

View File

@ -60,13 +60,13 @@ public class Xofulltext_searcher__brute implements Xofulltext_searcher {
// do highlight
if (found <= wiki_args.len) {
cbk_highlight.Init(ui, args.qry_id, wiki, page_id, ttl.Full_db(), args.show_all_snips);
cbk_highlight.Init(ui, args.qry_id, wiki, page_id, ttl.Full_db(), wiki_args.show_all_snips);
ui.Send_page_add(new Xofulltext_searcher_page
( args.qry_id
, wiki_domain
, page_id
, ttl.Full_db()
, args.expand_snips
, wiki_args.expand_snips
));
finder.Match(text_mcase, 0, text_mcase.length, cbk_highlight);
}

View File

@ -25,16 +25,18 @@ class Xofulltext_highlighter_mgr implements Gfo_invk {
private final Xofulltext_searcher_ui ui;
private final Xow_wiki wiki;
private final Xofulltext_args_qry searcher_args;
private final Xofulltext_args_wiki wiki_args;
private final Gflucene_analyzer_data analyzer_data;
private final Gflucene_searcher_qry searcher_data;
private final Gflucene_highlighter_mgr highlighter_mgr = new Gflucene_highlighter_mgr();
private final Xoh_page hpg = new Xoh_page();
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_args_qry searcher_args, Gflucene_analyzer_data analyzer_data, Gflucene_searcher_qry searcher_data, Ordered_hash list) {
public Xofulltext_highlighter_mgr(Xofulltext_searcher_ui ui, Xow_wiki wiki, Xofulltext_args_qry searcher_args, Xofulltext_args_wiki wiki_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;
this.wiki_args = wiki_args;
this.analyzer_data = analyzer_data;
this.searcher_data = searcher_data;
this.list = list;
@ -74,7 +76,7 @@ class Xofulltext_highlighter_mgr implements Gfo_invk {
int page_id = item.page_id;
Gflucene_highlighter_item[] lines = highlighter_mgr.Exec(searcher_data, item);
for (Gflucene_highlighter_item line : lines) {
ui.Send_line_add(true, searcher_args.show_all_snips, searcher_args.qry_id, wiki.Domain_bry(), page_id, line.num, Bry_.new_u8(line.text));
ui.Send_line_add(true, wiki_args.show_all_snips, searcher_args.qry_id, wiki.Domain_bry(), page_id, line.num, Bry_.new_u8(line.text));
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {

View File

@ -75,7 +75,7 @@ public class Xofulltext_searcher__lucene implements Xofulltext_searcher {
if (!wiki_args.ns_hash.Has(doc_data.ns_id)) continue;
// call page doc_data
Xofulltext_searcher_page page = new Xofulltext_searcher_page(args.qry_id, wiki.Domain_bry(), doc_data.page_id, doc_data.page_full_db, args.expand_snips);
Xofulltext_searcher_page page = new Xofulltext_searcher_page(args.qry_id, wiki.Domain_bry(), doc_data.page_id, doc_data.page_full_db, wiki_args.expand_snips);
ui.Send_page_add(page);
full_list.Add(doc_data.page_id, doc_data);
@ -92,7 +92,7 @@ public class Xofulltext_searcher__lucene implements Xofulltext_searcher {
ui.Send_wiki_update(wiki.Domain_bry(), page_list.Len(), -1);
// create highlighter thread and launch it
Xofulltext_highlighter_mgr highlighter_mgr = new Xofulltext_highlighter_mgr(ui, wiki, args, analyzer_data, searcher_data, full_list);
Xofulltext_highlighter_mgr highlighter_mgr = new Xofulltext_highlighter_mgr(ui, wiki, args, wiki_args, analyzer_data, searcher_data, full_list);
highlighter_mgr.Highlight_list(); // NOTE: do not launch in separate thread, else multiple wikis will have strange race conditions
}
}

View File

@ -28,15 +28,15 @@ class Xofulltext_searcher_html extends Xow_special_wtr__base implements Mustache
props.Add("cur_wiki", wiki.Domain_str());
props_Add_str(cfg_mgr, url_args, "wikis" , wiki.Domain_str(), false);
props_Add_str(cfg_mgr, url_args, "ns_ids", "0");
props_Add_str(cfg_mgr, url_args, "limits", "100");
props_Add_str(cfg_mgr, url_args, "limits", "25");
props_Add_str(cfg_mgr, url_args, "offsets", "0");
props_Add_str(cfg_mgr, url_args, "expand_snips", "n");
props_Add_str(cfg_mgr, url_args, "show_all_snips", "n");
props_Add_bool(cfg_mgr, url_args, "expand_snips");
props_Add_bool(cfg_mgr, url_args, "show_all_snips");
props_Add_bool(cfg_mgr, url_args, "expand_options");
props_Add_bool(cfg_mgr, url_args, "case_match");
props_Add_bool(cfg_mgr, url_args, "auto_wildcard_bgn");
props_Add_bool(cfg_mgr, url_args, "auto_wildcard_end");
props_Add_bool(cfg_mgr, url_args, "xowa.addon.fulltext_search.options", "expand_options");
props_Add_bool(cfg_mgr, url_args, "xowa.addon.fulltext_search.special", "case_match");
props_Add_bool(cfg_mgr, url_args, "xowa.addon.fulltext_search.special", "auto_wildcard_bgn");
props_Add_bool(cfg_mgr, url_args, "xowa.addon.fulltext_search.special", "auto_wildcard_end");
}
private void props_Add_str(Xocfg_mgr cfg_mgr, Gfo_qarg_mgr url_args, String key, String else_val) {
props_Add_str(cfg_mgr, url_args, key, else_val, true);
@ -44,14 +44,14 @@ class Xofulltext_searcher_html extends Xow_special_wtr__base implements Mustache
private void props_Add_str(Xocfg_mgr cfg_mgr, Gfo_qarg_mgr url_args, String key, String else_val, boolean use_cfg) {
String dflt_val = else_val;
if (use_cfg) {
String cfg_key = "xowa.addon.search.fulltext.special." + key;
String cfg_key = "xowa.addon.fulltext_search.special." + key;
dflt_val = cfg_mgr.Get_str_app_or(cfg_key, else_val);
}
props.Add("dflt_" + key, dflt_val);
props.Add("qarg_" + key, url_args.Read_str_or(key, dflt_val));
}
private void props_Add_bool(Xocfg_mgr cfg_mgr, Gfo_qarg_mgr url_args, String key) {
String cfg_key = "xowa.addon.search.fulltext.special." + key;
private void props_Add_bool(Xocfg_mgr cfg_mgr, Gfo_qarg_mgr url_args, String cfg_grp, String key) {
String cfg_key = cfg_grp + "." + key;
boolean cfg_val = cfg_mgr.Get_bool_app_or(cfg_key, false);
props.Add(key, cfg_val);
}

View File

@ -45,11 +45,7 @@ class Xofulltext_searcher_svc implements Gfo_invk {
}
public void Options_save(Json_nde args) {
Xocfg_mgr cfg_mgr = app.Cfg();
cfg_mgr.Set_bool_app("xowa.addon.search.fulltext.special.expand_options", args.Get_as_bool_or("expand_options", false));
if (cfg_mgr.Get_bool_app_or("xowa.addon.search.fulltext.options.autosave_enabled", true)) {
cfg_mgr.Set_bool_app("xowa.addon.search.fulltext.special.expand_snips", args.Get_as_bool_or("expand_snips", false));
cfg_mgr.Set_bool_app("xowa.addon.search.fulltext.special.show_all_snips", args.Get_as_bool_or("show_all_snips", false));
}
cfg_mgr.Set_bool_app("xowa.addon.fulltext_search.options.expand_options", args.Get_as_bool_or("expand_options", false));
}
public void Search_run(Json_nde args) {
// get search_args
@ -63,19 +59,6 @@ class Xofulltext_searcher_svc implements Gfo_invk {
wkr_hash.Add(search_args.page_guid, search_args);
}
// autosave any changes if enabled
// Xocfg_mgr cfg_mgr = app.Cfg();
// if (cfg_mgr.Get_bool_app_or("xowa.addon.search.fulltext.options.autosave_enabled", true)) {
// cfg_mgr.Set_bool_app("xowa.addon.search.fulltext.special.expand_snips", search_args.expand_snips);
// cfg_mgr.Set_bool_app("xowa.addon.search.fulltext.special.show_all_snips", search_args.show_all_snips);
// cfg_mgr.Set_bool_app("xowa.addon.search.fulltext.special.expand_options", search_args.expand_options);
// cfg_mgr.Set_bool_app("xowa.addon.search.fulltext.special.case_match", search_args.case_match);
// cfg_mgr.Set_bool_app("xowa.addon.search.fulltext.special.auto_wildcard_bgn", search_args.auto_wildcard_bgn);
// cfg_mgr.Set_bool_app("xowa.addon.search.fulltext.special.auto_wildcard_end", search_args.auto_wildcard_end);
//// cfg_mgr.Set_int_app ("xowa.addon.search.fulltext.special.max_pages_per_wiki", search_args.max_pages_per_wiki);
//// cfg_mgr.Set_bry_app ("xowa.addon.search.fulltext.special.namespaces", search_args.namespaces);
// }
// launch thread
gplx.core.threads.Thread_adp_.Start_by_val("search", Cancelable_.Never, this, Invk__search, search_args);
}
@ -138,13 +121,13 @@ class Xofulltext_searcher_svc implements Gfo_invk {
for (int i = bgn; i < end; i++) {
if (i >= max) return false; // more pages requested than available
Xofulltext_cache_page page = (Xofulltext_cache_page)qry.Pages().Get_at(i);
ui.Send_page_add(new Xofulltext_searcher_page(qry_id, wiki.Domain_bry(), page.Page_id(), page.Page_ttl(), args.expand_snips));
ui.Send_page_add(new Xofulltext_searcher_page(qry_id, wiki.Domain_bry(), page.Page_id(), page.Page_ttl(), wiki_args.expand_snips));
// loop lines
int lines_len = page.Lines().Len();
for (int j = 0; j < lines_len; j++) {
Xofulltext_cache_line line = (Xofulltext_cache_line)page.Lines().Get_at(j);
ui.Send_line_add(false, args.show_all_snips, qry_id, wiki.Domain_bry(), page.Page_id(), line.Line_seq(), line.Line_html());
ui.Send_line_add(false, wiki_args.show_all_snips, qry_id, wiki.Domain_bry(), page.Page_id(), line.Line_seq(), line.Line_html());
}
}
return true;