mirror of https://github.com/gnosygnu/xowa
Full-text search: Automatically execute search if search_text is available; also, add limited caching
parent
e486d139e0
commit
7924e26522
@ -0,0 +1,71 @@
|
||||
/*
|
||||
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.fulltexts.searchers.mgrs; 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.langs.jsons.*;
|
||||
import gplx.xowa.addons.wikis.fulltexts.searchers.caches.*;
|
||||
public class Xofulltext_args_qry {
|
||||
public int qry_id;
|
||||
public String page_guid;
|
||||
public byte[] search_text;
|
||||
public Xofulltext_cache_mgr cache_mgr;
|
||||
public Xofulltext_args_wiki[] wikis_ary;
|
||||
|
||||
public boolean case_match;
|
||||
public boolean auto_wildcard_bgn;
|
||||
public boolean auto_wildcard_end;
|
||||
public boolean expand_matches_section;
|
||||
public boolean show_all_matches;
|
||||
|
||||
public byte[] Qry_key(byte[] wiki, byte[] ns_ids) {
|
||||
return Bry_.Add_w_dlm(Byte_ascii.Nl, wiki, ns_ids, search_text); // EX: "en.wikipedia.org\n0|4\nearth"
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
// create wikis
|
||||
byte[] wikis_bry = args.Get_as_bry("qarg_wikis");
|
||||
byte[][] wikis_ary = Bry_split_.Split(wikis_bry, Byte_ascii.Pipe, true);
|
||||
int wikis_len = wikis_ary.length;
|
||||
Xofulltext_args_wiki[] wiki_args = new Xofulltext_args_wiki[wikis_len];
|
||||
rv.wikis_ary = wiki_args;
|
||||
for (int i = 0; i < wikis_len; i++) {
|
||||
wiki_args[i] = new Xofulltext_args_wiki(wikis_ary[i]);
|
||||
}
|
||||
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.case_match = args.Get_as_bool_or("case_match", false);
|
||||
rv.auto_wildcard_bgn = args.Get_as_bool_or("auto_wildcard_bgn", false);
|
||||
rv.auto_wildcard_end = args.Get_as_bool_or("auto_wildcard_end", false);
|
||||
rv.expand_matches_section = args.Get_as_bool_or("expand_matches_section", false);
|
||||
rv.show_all_matches = args.Get_as_bool_or("show_all_matches", false);
|
||||
return rv;
|
||||
}
|
||||
private static void Set_prop(Xofulltext_args_wiki[] wikis, int wikis_len, Json_nde args, String key) {
|
||||
// set ns_ids
|
||||
byte[] json_val = args.Get_as_bry("qarg_" + key);
|
||||
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];
|
||||
wikis[i].Init_by_json(key, val);
|
||||
}
|
||||
}
|
||||
}
|
@ -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.fulltexts.searchers.mgrs; 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.*;
|
||||
public class Xofulltext_args_wiki {
|
||||
public byte[] wiki;
|
||||
public byte[] ns_ids;
|
||||
public int offset;
|
||||
public int limit;
|
||||
|
||||
public Xofulltext_args_wiki(byte[] wiki) {
|
||||
this.wiki = wiki;
|
||||
}
|
||||
public void Init_by_json(String key, byte[] val) {
|
||||
if (String_.Eq(key, "ns_ids")) this.ns_ids = val;
|
||||
else if (String_.Eq(key, "offsets")) this.offset = Bry_.To_int(val);
|
||||
else if (String_.Eq(key, "limits")) this.limit = Bry_.To_int(val);
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
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.fulltexts.searchers.mgrs; 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.langs.jsons.*;
|
||||
public class Xofulltext_searcher_args {
|
||||
public boolean case_match;
|
||||
public boolean auto_wildcard_bgn;
|
||||
public boolean auto_wildcard_end;
|
||||
public boolean expand_matches_section;
|
||||
public boolean show_all_matches;
|
||||
public int max_pages_per_wiki;
|
||||
public byte[] wikis;
|
||||
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);
|
||||
rv.auto_wildcard_bgn = args.Get_as_bool_or("auto_wildcard_bgn", false);
|
||||
rv.auto_wildcard_end = args.Get_as_bool_or("auto_wildcard_end", false);
|
||||
rv.expand_matches_section = args.Get_as_bool_or("expand_matches_section", false);
|
||||
rv.show_all_matches = args.Get_as_bool_or("show_all_matches", false);
|
||||
rv.max_pages_per_wiki = args.Get_as_int_or("max_pages_per_wiki", 25);
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
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.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.langs.mustaches.*;
|
||||
public class Xofulltext_searcher_doc implements Mustache_doc_itm {
|
||||
private final byte[] query;
|
||||
private final boolean case_match, auto_wildcard_bgn, auto_wildcard_end, expand_matches_section, show_all_matches;
|
||||
private final int max_pages_per_wiki;
|
||||
private final String wikis, namespaces;
|
||||
public Xofulltext_searcher_doc
|
||||
( byte[] query, boolean case_match, boolean auto_wildcard_bgn, boolean auto_wildcard_end
|
||||
, boolean expand_matches_section, boolean show_all_matches
|
||||
, int max_pages_per_wiki
|
||||
, String wikis, String namespaces) {
|
||||
this.query = query;
|
||||
this.case_match = case_match;
|
||||
this.auto_wildcard_bgn = auto_wildcard_bgn;
|
||||
this.auto_wildcard_end = auto_wildcard_end;
|
||||
this.expand_matches_section = expand_matches_section;
|
||||
this.show_all_matches = show_all_matches;
|
||||
this.max_pages_per_wiki = max_pages_per_wiki;
|
||||
this.wikis = wikis;
|
||||
this.namespaces = namespaces;
|
||||
}
|
||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||
if (String_.Eq(key, "wikis"))
|
||||
bfr.Add_str_u8(wikis);
|
||||
else if (String_.Eq(key, "namespaces"))
|
||||
bfr.Add_str_u8(namespaces);
|
||||
else if (String_.Eq(key, "max_pages_per_wiki"))
|
||||
bfr.Add_int(max_pages_per_wiki);
|
||||
else if (String_.Eq(key, "query"))
|
||||
bfr.Add_bry(query);
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {
|
||||
if (String_.Eq(key, "case_match"))
|
||||
return Mustache_doc_itm_.Ary__bool(case_match);
|
||||
else if (String_.Eq(key, "auto_wildcard_bgn"))
|
||||
return Mustache_doc_itm_.Ary__bool(auto_wildcard_bgn);
|
||||
else if (String_.Eq(key, "auto_wildcard_end"))
|
||||
return Mustache_doc_itm_.Ary__bool(auto_wildcard_end);
|
||||
else if (String_.Eq(key, "expand_matches_section"))
|
||||
return Mustache_doc_itm_.Ary__bool(expand_matches_section);
|
||||
else if (String_.Eq(key, "show_all_matches"))
|
||||
return Mustache_doc_itm_.Ary__bool(show_all_matches);
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
}
|
@ -1 +1 @@
|
||||
add sponsors
|
||||
add hindi and tibetan wikis
|
||||
|
Loading…
Reference in new issue