Search in sources :

Example 1 with Field

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;
}
Also used : Field(io.github.ihongs.dh.search.StatisHandle.Field) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with Field

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);
    }
}
Also used : Field(io.github.ihongs.dh.search.StatisHandle.Field) Query(org.apache.lucene.search.Query) HongsException(io.github.ihongs.HongsException) IOException(java.io.IOException)

Example 3 with Field

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;
}
Also used : Field(io.github.ihongs.dh.search.StatisHandle.Field) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Field

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);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Field(io.github.ihongs.dh.search.StatisHandle.Field) Query(org.apache.lucene.search.Query) HongsException(io.github.ihongs.HongsException) IOException(java.io.IOException)

Example 5 with Field

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()]);
}
Also used : Field(io.github.ihongs.dh.search.StatisHandle.Field) HongsException(io.github.ihongs.HongsException) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) TYPE(io.github.ihongs.dh.search.StatisHandle.TYPE)

Aggregations

Field (io.github.ihongs.dh.search.StatisHandle.Field)6 HongsException (io.github.ihongs.HongsException)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Query (org.apache.lucene.search.Query)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)2 TYPE (io.github.ihongs.dh.search.StatisHandle.TYPE)1 ArrayList (java.util.ArrayList)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1