<commit_before>/**
 * Logspace
 * Copyright (c) 2016 Indoqa Software Design und Beratung GmbH. All rights reserved.
 * This program and the accompanying materials are made available under the terms of
 * the Eclipse Public License Version 1.0, which accompanies this distribution and
 * is available at http://www.eclipse.org/legal/epl-v10.html.
 */
package io.logspace.hq.solr;

import static com.indoqa.lang.util.StringUtils.escapeSolr;
import static com.indoqa.lang.util.TimeUtils.formatSolrDate;
import static io.logspace.hq.solr.EventFieldConstants.FIELD_TIMESTAMP;

import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.apache.solr.client.solrj.SolrQuery;

import io.logspace.agent.api.order.PropertyDescription;
import io.logspace.agent.api.order.PropertyType;
import io.logspace.hq.rest.api.timeseries.TimeWindow;

/*default*/ final class SolrQueryHelper {

    public static final String ALL_DOCS_QUERY = "*:*";
    public static final String SORT_CRON_ASC = "timestamp ASC, id ASC";
    public static final String SORT_CRON_DESC = "timestamp DESC, id ASC";

    public static final String VALUE_FACET_NAME = "val";
    public static final String AGGREGATION_FACET_NAME = "agg";
    public static final String COUNT_FACET_NAME = "count";

    private SolrQueryHelper() {
        // hide utility class constructor
    }

    public static void addFilterQuery(SolrQuery solrQuery, String fieldName, String value) {
        if (StringUtils.isBlank(value)) {
            return;
        }

        solrQuery.addFilterQuery(fieldName + ":" + escapeSolr(value));
    }

    public static PropertyDescription createPropertyDescription(String propertyId) {
        if (propertyId == null) {
            return null;
        }

        Pattern propertyIdPattern = Pattern.compile("(\\w+)_property_(.*?)");
        Matcher matcher = propertyIdPattern.matcher(propertyId);
        if (!matcher.matches()) {
            return null;
        }

        PropertyDescription result = new PropertyDescription();<commit_msg>SolrQueryHelper: regex pattern -> static<commit_after>/**
 * Logspace
 * Copyright (c) 2016 Indoqa Software Design und Beratung GmbH. All rights reserved.
 * This program and the accompanying materials are made available under the terms of
 * the Eclipse Public License Version 1.0, which accompanies this distribution and
 * is available at http://www.eclipse.org/legal/epl-v10.html.
 */
package io.logspace.hq.solr;

import static com.indoqa.lang.util.StringUtils.escapeSolr;
import static com.indoqa.lang.util.TimeUtils.formatSolrDate;
import static io.logspace.hq.solr.EventFieldConstants.FIELD_TIMESTAMP;

import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.apache.solr.client.solrj.SolrQuery;

import io.logspace.agent.api.order.PropertyDescription;
import io.logspace.agent.api.order.PropertyType;
import io.logspace.hq.rest.api.timeseries.TimeWindow;

/*default*/ final class SolrQueryHelper {

    public static final String ALL_DOCS_QUERY = "*:*";
    public static final String SORT_CRON_ASC = "timestamp ASC, id ASC";
    public static final String SORT_CRON_DESC = "timestamp DESC, id ASC";

    public static final String VALUE_FACET_NAME = "val";
    public static final String AGGREGATION_FACET_NAME = "agg";
    public static final String COUNT_FACET_NAME = "count";

    private static final Pattern PATTERN_PROPERTY_ID = Pattern.compile("(\\w+)_property_(.*?)");

    private SolrQueryHelper() {
        // hide utility class constructor
    }

    public static void addFilterQuery(SolrQuery solrQuery, String fieldName, String value) {
        if (StringUtils.isBlank(value)) {
            return;
        }

        solrQuery.addFilterQuery(fieldName + ":" + escapeSolr(value));
    }

    public static PropertyDescription createPropertyDescription(String propertyId) {
        if (propertyId == null) {
            return null;
        }

        Matcher matcher = PATTERN_PROPERTY_ID.matcher(propertyId);
        if (!matcher.matches()) {
            return null;
        }

        PropertyDescription result = new PropertyDescription();
{'fraction_non_alphanumeric': 0.0955174841586482, 'fraction_numerical': 0.004224360478760855, 'mean_word_length': 3.663019693654267, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '421782', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1217, 'n_words': 321}