use of app.hongs.HongsException in project HongsCORE by ihongs.
the class LuceneRecord method getAnalyser.
/**
* 查询分析器
* @param fc 字段配置
* @return
* @throws HongsException
*/
protected Analyzer getAnalyser(Map fc) throws HongsException {
try {
CustomAnalyzer.Builder cb = CustomAnalyzer.builder();
String kn, an, ac;
Map oc;
// 分词器
an = Synt.declare(fc.get("lucene-tokenizer"), "");
if (!"".equals(an)) {
int p = an.indexOf('{');
if (p != -1) {
ac = an.substring(p);
an = an.substring(0, p - 1).trim();
oc = Synt.asMap(Data.toObject(ac));
cb.withTokenizer(an, oc);
} else {
cb.withTokenizer(an);
}
} else {
cb.withTokenizer("Standard");
}
// 过滤器
for (Object ot2 : fc.entrySet()) {
Map.Entry et2 = (Map.Entry) ot2;
kn = (String) et2.getKey();
// 查询参数为 find,query
if (kn.startsWith("lucene-find-filter")) {
an = (String) et2.getValue();
an = an.trim();
if ("".equals(an)) {
continue;
}
int p = an.indexOf('{');
if (p != -1) {
ac = an.substring(p);
an = an.substring(0, p - 1).trim();
oc = Synt.asMap(Data.toObject(ac));
cb.addCharFilter(an, oc);
} else {
cb.addCharFilter(an);
}
} else if (kn.startsWith("lucene-query-filter")) {
an = (String) et2.getValue();
an = an.trim();
if ("".equals(an)) {
continue;
}
int p = an.indexOf('{');
if (p != -1) {
ac = an.substring(p);
an = an.substring(0, p - 1).trim();
oc = Synt.asMap(Data.toObject(ac));
cb.addTokenFilter(an, oc);
} else {
cb.addTokenFilter(an);
}
}
}
return cb.build();
} catch (IOException ex) {
throw new HongsException.Common(ex);
} catch (IllegalArgumentException ex) {
throw new HongsException.Common(ex);
}
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class LuceneRecord method getAnalyzer.
/**
* 存储分析器
* @param fc 字段配置
* @return
* @throws HongsException
*/
protected Analyzer getAnalyzer(Map fc) throws HongsException {
try {
CustomAnalyzer.Builder cb = CustomAnalyzer.builder();
String kn, an, ac;
Map oc;
// 分词器
an = Synt.declare(fc.get("lucene-tokenizer"), "");
if (!"".equals(an)) {
int p = an.indexOf('{');
if (p != -1) {
ac = an.substring(p);
an = an.substring(0, p - 1).trim();
oc = Synt.asMap(Data.toObject(ac));
cb.withTokenizer(an, oc);
} else {
cb.withTokenizer(an);
}
} else {
cb.withTokenizer("Standard");
}
// 过滤器
for (Object ot2 : fc.entrySet()) {
Map.Entry et2 = (Map.Entry) ot2;
kn = (String) et2.getKey();
// 存储参数为 char,token
if (kn.startsWith("lucene-char-filter")) {
an = (String) et2.getValue();
an = an.trim();
if ("".equals(an)) {
continue;
}
int p = an.indexOf('{');
if (p != -1) {
ac = an.substring(p);
an = an.substring(0, p - 1).trim();
oc = Synt.asMap(Data.toObject(ac));
cb.addCharFilter(an, oc);
} else {
cb.addCharFilter(an);
}
} else if (kn.startsWith("lucene-token-filter")) {
an = (String) et2.getValue();
an = an.trim();
if ("".equals(an)) {
continue;
}
int p = an.indexOf('{');
if (p != -1) {
ac = an.substring(p);
an = an.substring(0, p - 1).trim();
oc = Synt.asMap(Data.toObject(ac));
cb.addTokenFilter(an, oc);
} else {
cb.addTokenFilter(an);
}
}
}
return cb.build();
} catch (IOException ex) {
throw new HongsException.Common(ex);
} catch (IllegalArgumentException ex) {
throw new HongsException.Common(ex);
}
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class SearchCmdlet method update.
@Cmdlet("update")
public void update(String[] args) throws HongsException {
Map opts = CmdletHelper.getOpts(args, new String[] { "conf=s", "name=s", "id*s" });
String conf = Synt.asString(opts.remove("conf"));
String name = Synt.asString(opts.remove("name"));
List<String> ds = Synt.asList(opts.remove("id"));
ActionHelper ah = Core.getInstance(ActionHelper.class);
LuceneRecord so = LuceneRecord.getInstance(conf, name);
Map rd = ah.getRequestData();
if (!rd.isEmpty()) {
// 有数据则校验数据
VerifyHelper vh = new VerifyHelper();
vh.addRulesByForm(conf, name);
rd = vh.verify(rd);
try {
so.begin();
for (String id : ds) {
so.set(id, rd);
}
so.commit();
} catch (HongsException ex) {
so.revert();
throw ex;
} finally {
so.close();
}
} else {
// 不给内容即为删除
try {
so.begin();
for (String id : ds) {
so.del(id);
}
so.commit();
} catch (HongsException ex) {
so.revert();
throw ex;
} finally {
so.close();
}
}
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class SearchHelper method counts.
private int counts(Map rd, Map<String, Map<String, Integer>> counts, Map<String, Map<String, Integer>> countz, Map<String, Set<String>> countx, IndexReader reader, IndexSearcher finder) throws HongsException {
int total = 0;
try {
Query q = that.getQuery(rd);
if (0 < Core.DEBUG && 8 != (8 & Core.DEBUG)) {
CoreLogger.debug("SearchRecord.counts: " + q.toString());
}
TopDocs docz = finder.search(q, 500);
while (docz.totalHits > 0) {
ScoreDoc[] docs = docz.scoreDocs;
if (!countz.isEmpty() || !counts.isEmpty()) {
for (ScoreDoc dox : docs) {
Document doc = reader.document(dox.doc);
for (Map.Entry<String, Map<String, Integer>> et : countz.entrySet()) {
String k = et.getKey();
Map<String, Integer> cntc = et.getValue();
IndexableField[] vals = doc.getFields(k);
for (IndexableField vol : vals) {
String val = vol.stringValue();
val = getValue(val, k);
if (cntc.containsKey(val)) {
cntc.put(val, cntc.get(val) + 1);
}
}
}
for (Map.Entry<String, Map<String, Integer>> et : counts.entrySet()) {
String k = et.getKey();
Map<String, Integer> cntc = et.getValue();
IndexableField[] vals = doc.getFields(k);
Map<String, Integer> cntu = countz.get(k);
Set<String> cntx = countx.get(k);
Set<String> cntv = cntu != null ? cntu.keySet() : null;
for (IndexableField vol : vals) {
String val = vol.stringValue();
val = getValue(val, k);
if (cntc.containsKey(val)) {
cntc.put(val, cntc.get(val) + 1);
} else if ((cntv == null || !cntv.contains(val)) && (cntx == null || !cntx.contains(val))) {
cntc.put(val, 1);
}
}
}
}
}
if (docs.length > 0) {
docz = finder.searchAfter(docs[docs.length - 1], q, 500);
total += docs.length;
} else {
break;
}
}
} catch (IOException ex) {
throw new HongsException.Common(ex);
}
return total;
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class SearchHelper method statis.
private int statis(Map rd, Map<String, Map<Minmax, Cntsum>> counts, Map<String, Set<Minmax>> countx, IndexReader reader, IndexSearcher finder) throws HongsException {
int total = 0;
try {
Query q = that.getQuery(rd);
if (0 < Core.DEBUG && 8 != (8 & Core.DEBUG)) {
CoreLogger.debug("SearchRecord.statis: " + q.toString());
}
TopDocs docz = finder.search(q, 500);
while (docz.totalHits > 0) {
ScoreDoc[] docs = docz.scoreDocs;
if (!counts.isEmpty()) {
for (ScoreDoc dox : docs) {
Document doc = reader.document(dox.doc);
for (Map.Entry<String, Map<Minmax, Cntsum>> et : counts.entrySet()) {
String k = et.getKey();
Map<Minmax, Cntsum> cntc = et.getValue();
Set<Minmax> cntx = countx.get(k);
IndexableField[] vals = doc.getFields(k);
F: for (IndexableField x : vals) {
double v = x.numericValue().doubleValue();
v = getValue(v, k);
for (Map.Entry<Minmax, Cntsum> mc : cntc.entrySet()) {
Minmax m = mc.getKey();
/*
* 注意:
* 总计并没有跳过需忽略的值,
* 忽略的值仅表示不进行统计;
* 如果需要从结果中排除记录,
* 应在wr或ar参数中进行指定.
*/
if (!m.covers()) {
if (!m.covers(v)) {
continue;
}
if (cntx != null)
for (Minmax w : cntx) {
if (w.covers(v)) {
continue F;
}
}
}
mc.getValue().add(v);
}
}
}
}
}
if (docs.length > 0) {
docz = finder.searchAfter(docs[docs.length - 1], q, 500);
total += docs.length;
} else {
break;
}
}
} catch (IOException ex) {
throw new HongsException.Common(ex);
}
return total;
}
Aggregations