mirror of
https://github.com/gnosygnu/xowa.git
synced 2025-05-31 22:44:34 +00:00
Full-text search: Add fallback behavior to Special:Search if index is not available
This commit is contained in:
parent
62d7e6adfe
commit
541b6e461d
@ -20,7 +20,7 @@ import gplx.xowa.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wik
|
||||
import gplx.xowa.addons.apps.cfgs.*;
|
||||
class Xofulltext_searcher_html extends Xow_special_wtr__base implements Mustache_doc_itm {
|
||||
private final Hash_adp props = Hash_adp_.New();
|
||||
public Xofulltext_searcher_html(Xocfg_mgr cfg_mgr, Gfo_qarg_mgr url_args, Xow_wiki wiki, Guid_adp page_guid) {
|
||||
public Xofulltext_searcher_html(Xocfg_mgr cfg_mgr, Gfo_qarg_mgr url_args, Xow_wiki wiki, Guid_adp page_guid, boolean lucene_exists) {
|
||||
String search_text = url_args.Read_str_or("search", "");
|
||||
search_text = String_.Replace(search_text, "_", " "); // xofulltext_searcher.js chains multiple words with "_"; convert back to space
|
||||
props.Add("qarg_search", search_text);
|
||||
@ -29,7 +29,6 @@ class Xofulltext_searcher_html extends Xow_special_wtr__base implements Mustache
|
||||
|
||||
// enabled
|
||||
boolean app_is_drd = gplx.core.envs.Op_sys.Cur().Tid_is_drd();
|
||||
boolean lucene_exists = Io_mgr.Instance.ExistsDir(gplx.xowa.addons.wikis.fulltexts.Xosearch_fulltext_addon.Get_index_dir(wiki));
|
||||
props.Add("app_is_drd", app_is_drd); // for options button
|
||||
props.Add("disabled", app_is_drd && !lucene_exists);
|
||||
|
||||
|
@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.fulltexts.searchers.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.fulltexts.*; import gplx.xowa.addons.wikis.fulltexts.searchers.*;
|
||||
import gplx.xowa.specials.*; import gplx.core.net.qargs.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.addons.apps.cfgs.*;
|
||||
public class Xofulltext_searcher_special implements Xow_special_page {
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
@ -22,8 +23,22 @@ public class Xofulltext_searcher_special implements Xow_special_page {
|
||||
Gfo_qarg_mgr url_args = new Gfo_qarg_mgr().Init(url.Qargs_ary());
|
||||
Xocfg_mgr cfg_mgr = wiki.App().Cfg();
|
||||
|
||||
// redirect to Special:Search if index doesn't exist
|
||||
boolean lucene_exists = Io_mgr.Instance.ExistsDir(gplx.xowa.addons.wikis.fulltexts.Xosearch_fulltext_addon.Get_index_dir(wiki));
|
||||
if ( !gplx.core.envs.Op_sys.Cur().Tid_is_drd() // desktop
|
||||
&& !lucene_exists // no lucene index
|
||||
&& !Int_.In(wiki.Domain_tid(), Xow_domain_tid_.Tid__home, Xow_domain_tid_.Tid__other) // not home or personal wiki
|
||||
&& !Bry_.Eq(url_args.Read_bry_or_null("force"), Bool_.Y_bry) // force=y is not present in url
|
||||
&& wiki.App().Cfg().Get_bool_app_or(gplx.xowa.apps.cfgs.Xocfg_win.Cfg__search__fallback_to_title, true) // cfg.fallback is enabled
|
||||
) {
|
||||
Xoa_ttl redirect_ttl = wiki.Ttl_parse(Bry_.new_u8("Special:Search?fulltext=y&search=" + url_args.Read_str_or("search", "")));
|
||||
Xoa_url redirect_url = wiki.Utl__url_parser().Parse(redirect_ttl.Full_db());
|
||||
page.Redirect_trail().Itms__add__article(redirect_url, redirect_ttl, null);
|
||||
return;
|
||||
}
|
||||
|
||||
// create page
|
||||
Xofulltext_searcher_html html = new Xofulltext_searcher_html(cfg_mgr, url_args, wiki, page.Page_guid());
|
||||
Xofulltext_searcher_html html = new Xofulltext_searcher_html(cfg_mgr, url_args, wiki, page.Page_guid(), lucene_exists);
|
||||
html.Bld_page_by_mustache(wiki.App(), page, this);
|
||||
}
|
||||
Xofulltext_searcher_special(Xow_special_meta special__meta) {this.special__meta = special__meta;}
|
||||
|
@ -22,7 +22,7 @@ public class Rndm_page_special implements Xow_special_page {
|
||||
// Rndm_addon.Get(wiki).Mgr().Get_rndm_page_by_ns(ns);
|
||||
|
||||
byte[] random_ttl_bry = wiki.Db_mgr().Load_mgr().Find_random_ttl(ns);
|
||||
wiki.Data_mgr().Redirect(page, ns.Gen_ttl(random_ttl_bry));
|
||||
wiki.Data_mgr().Redirect(page, ns.Gen_ttl(random_ttl_bry)); // REDIRECT:as per Special:Random
|
||||
}
|
||||
|
||||
public static final String SPECIAL_KEY = "Randompage"; // NOTE: needs to match lang.gfs
|
||||
|
@ -52,7 +52,9 @@ public class Xocfg_win implements Gfo_invk {
|
||||
private static final String Invk_search_box_fmt_ = "search_box_fmt_", Invk_font = "font";
|
||||
private static final String
|
||||
Cfg__search__default_to_fulltext = "xowa.addon.fulltext_search.compatibility.default_to_fulltext"
|
||||
, Cfg__search__fallback_to_title = "xowa.addon.fulltext_search.compatibility.fallback_to_title";
|
||||
;
|
||||
public static final String
|
||||
Cfg__search__fallback_to_title = "xowa.addon.fulltext_search.compatibility.fallback_to_title";
|
||||
|
||||
public static final float Font_size_default = 8;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user