use of io.github.ihongs.dh.search.StatisHandle.Field in project HongsCORE by ihongs.
the class StatisGrader method amount.
/**
* 数值计算
* @return
*/
public Map<String, Map<Range, Ratio>> amount() throws IOException {
Map<String, Map<Range, Ratio>> counts = new HashMap();
Map<String, Set<Range>> countx = new HashMap();
for (Field field : fields) {
counts.put(field.alias, new HashMap());
}
if (query == null) {
query = new MatchAllDocsQuery();
}
finder.search(query, new Amount(fields, counts, countx));
return counts;
}
use of io.github.ihongs.dh.search.StatisHandle.Field in project HongsCORE by ihongs.
the class StatisHelper method acount.
private int acount(Map rd, IndexSearcher finder, Map<String, Map<Object, Long>> counts, Map<String, Set<Object>> countx) throws HongsException {
Field[] fields = getGraderFields(counts.keySet(), rd);
try {
Query q = that.padQry(rd);
if (4 == (4 & Core.DEBUG)) {
CoreLogger.debug("StatisHelper.acount: " + q.toString());
}
if (counts.isEmpty()) {
return finder.count(q);
}
StatisGrader.Acount c = new StatisGrader.Acount(fields, counts, countx);
finder.search(q, c);
return c.count();
} catch (IOException e) {
throw new HongsException(e);
}
}
use of io.github.ihongs.dh.search.StatisHandle.Field in project HongsCORE by ihongs.
the class StatisGrader method acount.
/**
* 分类统计
* @return
* @throws IOException
*/
public Map<String, Map<Object, Long>> acount() throws IOException {
Map<String, Map<Object, Long>> counts = new HashMap();
Map<String, Set<Object>> countx = new HashMap();
for (Field field : fields) {
counts.put(field.alias, new HashMap());
}
if (query == null) {
query = new MatchAllDocsQuery();
}
finder.search(query, new Acount(fields, counts, countx));
return counts;
}
use of io.github.ihongs.dh.search.StatisHandle.Field in project HongsCORE by ihongs.
the class StatisHelper method search.
/**
* 统计查询
* @param rd
* @param fx
*/
public void search(Map rd, final Consumer<Field[]> fx) throws HongsException {
Set<String> rb = Synt.toTerms(rd.get(Cnst.RB_KEY));
if (rb == null || rb.isEmpty()) {
throw new NullPointerException("Search fields required.");
}
Field[] fs = getGraderFields(rb, rd);
if (fs == null || fs.length == 0) {
throw new NullPointerException("Search fields required!");
}
try {
Query q = that.padQry(rd);
if (4 == (4 & Core.DEBUG)) {
CoreLogger.debug("StatisHelper.search: " + q.toString());
}
IndexSearcher finder = that.getFinder();
StatisHandle.Fetch c = new StatisHandle.Fetch(fx, fs);
finder.search(q, c);
} catch (IOException e) {
throw new HongsException(e);
}
}
use of io.github.ihongs.dh.search.StatisHandle.Field in project HongsCORE by ihongs.
the class StatisHelper method getGraderFields.
private Field[] getGraderFields(Set<String> names, Map rd) {
if (names == null) {
return null;
}
List<Field> fields = new ArrayList(names.size());
Map<String, Map> items = that.getFields();
Map<String, String> types;
try {
types = FormSet.getInstance().getEnum("__types__");
} catch (HongsException e) {
throw e.toExemption();
}
for (String n : names) {
TYPE g;
String f = n;
Map c = items.get(f);
if (c == null) {
continue;
}
String t = (String) c.get("__type__");
Object k = (Object) c.get("type");
// 使用基准类型
if (types.containsKey(t)) {
t = types.get(t);
}
if (Synt.declare(c.get("__repeated__"), false) == false) {
f = "#" + f;
if (null != t)
switch(t) {
case "number":
if ("int".equals(k) || "byte".equals(k) || "short".equals(k)) {
g = TYPE.INT;
} else if ("long".equals(k)) {
g = TYPE.LONG;
} else if ("float".equals(k)) {
g = TYPE.FLOAT;
} else {
g = TYPE.DOUBLE;
}
break;
case "hidden":
case "enum":
if ("int".equals(k) || "byte".equals(k) || "short".equals(k)) {
g = TYPE.INT;
} else if ("long".equals(k)) {
g = TYPE.LONG;
} else if ("float".equals(k)) {
g = TYPE.FLOAT;
} else if ("double".equals(k) || "number".equals(k)) {
g = TYPE.DOUBLE;
} else {
g = TYPE.STRING;
}
break;
case "date":
g = TYPE.LONG;
break;
default:
g = TYPE.STRING;
}
else {
g = TYPE.STRING;
}
} else {
f = "%" + f;
if (null != t)
switch(t) {
case "number":
if ("int".equals(k) || "byte".equals(k) || "short".equals(k)) {
g = TYPE.INTS;
} else if ("long".equals(k)) {
g = TYPE.LONGS;
} else if ("float".equals(k)) {
g = TYPE.FLOATS;
} else {
g = TYPE.DOUBLES;
}
break;
case "hidden":
case "enum":
if ("int".equals(k) || "byte".equals(k) || "short".equals(k)) {
g = TYPE.INTS;
} else if ("long".equals(k)) {
g = TYPE.LONGS;
} else if ("float".equals(k)) {
g = TYPE.FLOATS;
} else if ("double".equals(k) || "number".equals(k)) {
g = TYPE.DOUBLES;
} else {
g = TYPE.STRINGS;
}
break;
case "date":
g = TYPE.LONGS;
break;
default:
g = TYPE.STRINGS;
}
else {
g = TYPE.STRINGS;
}
}
fields.add(new Field(g, f, n));
}
return fields.toArray(new Field[fields.size()]);
}
Aggregations