<commit_before>/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package org.springside.modules.persistence;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.lang3.StringUtils;

import com.google.common.collect.Maps;

import static org.springside.modules.persistence.SearchFilter.Type.DATETIME;

public class SearchFilter {

    public enum Operator {
        EQ, NEQ, LIKE, LIKEP, PLIKE, GT, LT, GTE, LTE, IN
    }

    public enum Type {
        DATETIME
    }

    public String fieldName;
    public Object value;
    public Operator operator;

    public SearchFilter(String fieldName, Operator operator, Object value) {
        this.fieldName = fieldName;
        this.value = value;
        this.operator = operator;
    }

    /**
     * searchParams中key的格式为OPERATOR_FIELDNAME
     */
    public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) {
        Map<String, SearchFilter> filters = Maps.newHashMap();

        for (Entry<String, Object> entry : searchParams.entrySet()) {
            // 过滤掉空值
            String key = entry.getKey();
            Object value = entry.getValue();
            if (value == null) {
                continue;
            }

            if (value instanceof String) {
                if (StringUtils.isBlank((String) value)) {
                    continue;
                }
            }

            // 拆分operator与filedAttribute
            String[] names = StringUtils.split(key, "_");
            if (names.length < 2 || names.length > 3) {
                throw new IllegalArgumentException(key + " is not a valid search filter name");
            }
            String filedName = names[1];
            Operator operator = Operator.valueOf(names[0]);
            if (names.length == 3) {
                switch (Type.valueOf(names[2])) {
                    case DATETIME:
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        try {
                            value = sdf.parse(value.toString());
                        } catch (ParseException e) {
                            throw new IllegalArgumentException(key + " is not the time format yyyy-MM-dd HH: mm: ss");
                        }
                        break;
                }
            }

            // 创建searchFilter
            SearchFilter filter = new SearchFilter(filedName, operator, value);
            filters.put(key, filter);
        }

        return filters;
    }
}
<commit_msg>修改时间类型查询<commit_after>/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package org.springside.modules.persistence;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.lang3.StringUtils;

import com.google.common.collect.Maps;

import static org.springside.modules.persistence.SearchFilter.Type.DATETIME;

public class SearchFilter {

    public enum Operator {
        EQ, NEQ, LIKE, LIKEP, PLIKE, GT, LT, GTE, LTE, IN
    }

    public enum Type {
        DATETIME
    }

    public String fieldName;
    public Object value;
    public Operator operator;

    public SearchFilter(String fieldName, Operator operator, Object value) {
        this.fieldName = fieldName;
        this.value = value;
        this.operator = operator;
    }

    /**
     * searchParams中key的格式为OPERATOR_FIELDNAME
     */
    public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) {
        Map<String, SearchFilter> filters = Maps.newHashMap();

        for (Entry<String, Object> entry : searchParams.entrySet()) {
            // 过滤掉空值
            String key = entry.getKey();
            Object value = entry.getValue();
            if (value == null) {
                continue;
            }

            if (value instanceof String) {
                if (StringUtils.isBlank((String) value)) {
                    continue;
                }
            }

            // 拆分operator与filedAttribute
            String[] names = StringUtils.split(key, "_");
            if (names.length < 2 || names.length > 3) {
                throw new IllegalArgumentException(key + " is not a valid search filter name");
            }
            String filedName = names[1];
            Operator operator = Operator.valueOf(names[0]);
            if (names.length == 3) {
                switch (Type.valueOf(names[2])) {
                    case DATETIME:
                        if (value instanceof Date) {
                        } else {
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            try {
                                value = sdf.parse(value.toString());
                            } catch (ParseException e) {
                                throw new IllegalArgumentException(key + " is not the time format yyyy-MM-dd HH: mm: ss");
                            }
                        }
                        break;
                }
            }

            // 创建searchFilter
            SearchFilter filter = new SearchFilter(filedName, operator, value);
            filters.put(key, filter);
        }

        return filters;
    }
}

{'fraction_non_alphanumeric': 0.14543889845094665, 'fraction_numerical': 0.00585197934595525, 'mean_word_length': 1.820873786407767, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '142741', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1440, 'n_words': 361}