Search in sources :

Example 11 with Field

use of de.tblsoft.solr.pipeline.bean.Field in project solr-cmd-utils by tblsoft.

the class ElasticWriter method mapToJson.

static Map<String, Object> mapToJson(Document document, boolean detectNumberValues) {
    Map<String, Object> jsonDocument = new HashMap<String, Object>();
    for (Field field : document.getFields()) {
        List<String> values = field.getValues();
        if (values == null || values.isEmpty()) {
            continue;
        }
        boolean fieldIsFlat = field.getName().contains(".");
        String fieldName = field.getName();
        Object fieldValue = field.getValues();
        if (values.size() == 1) {
            fieldValue = transformDatatype(field.getValue(), detectNumberValues);
        }
        if (fieldIsFlat) {
            fieldValue = createExpandedValue(fieldName, fieldValue);
            fieldName = StringUtils.substringBefore(fieldName, ".");
        }
        jsonDocument.put(fieldName, fieldValue);
    }
    return jsonDocument;
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field)

Example 12 with Field

use of de.tblsoft.solr.pipeline.bean.Field in project solr-cmd-utils by tblsoft.

the class FieldJoiner method document.

@Override
public void document(Document document) {
    Map<String, String> documentMap = new HashMap<String, String>();
    for (Field field : document.getFields()) {
        documentMap.put(field.getName(), field.getValue());
    }
    StrSubstitutor sub = new StrSubstitutor(documentMap);
    String value = sub.replace(output);
    document.addField(outputField, value);
    super.document(document);
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field) StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) HashMap(java.util.HashMap)

Example 13 with Field

use of de.tblsoft.solr.pipeline.bean.Field in project solr-cmd-utils by tblsoft.

the class StatisticFilter method document.

@Override
public void document(Document document) {
    for (Field field : document.getFields()) {
        for (Pair<String, String> dynamicField : dynamicFields) {
            if (field.getName().matches(dynamicField.getLeft())) {
                field.setName(dynamicField.getRight());
            }
        }
        FieldStatistic fieldStatistic = fieldStatisticMap.get(field.getName());
        if (fieldStatistic == null) {
            fieldStatistic = new FieldStatistic(field.getName());
            fieldStatisticMap.put(field.getName(), fieldStatistic);
        }
        fieldStatistic.maxValueCount(field.getValues().size());
        for (String value : field.getValues()) {
            fieldStatistic.processValue(value);
        }
    }
    documentCount++;
    super.document(document);
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field)

Example 14 with Field

use of de.tblsoft.solr.pipeline.bean.Field in project solr-cmd-utils by tblsoft.

the class SystemOutWriter method document.

@Override
public void document(Document document) {
    documentCounter++;
    List<Field> values = document.getFields();
    if (values != null) {
        for (Field f : values) {
            fieldCounter++;
            System.out.print(prefix + "name: " + f.getName());
            String out = Joiner.on(", ").skipNulls().join(f.getValues());
            System.out.println(prefix + " -- value: " + out);
        }
    }
    super.document(document);
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field)

Example 15 with Field

use of de.tblsoft.solr.pipeline.bean.Field in project solr-cmd-utils by tblsoft.

the class AggregationCountFilter method document.

@Override
public void document(Document document) {
    for (Field field : document.getFields()) {
        AtomicLongMap<String> countMap = aggregation.get(field.getName());
        if (countMap == null) {
            countMap = AtomicLongMap.create();
        }
        for (String value : field.getValues()) {
            countMap.incrementAndGet(value);
        }
        aggregation.put(field.getName(), countMap);
    }
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field)

Aggregations

Field (de.tblsoft.solr.pipeline.bean.Field)27 Document (de.tblsoft.solr.pipeline.bean.Document)8 Test (org.junit.Test)5 AbstractFilterTest (de.tblsoft.solr.pipeline.test.AbstractFilterTest)4 Ignore (org.junit.Ignore)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 StrSubstitutor (org.apache.commons.lang3.text.StrSubstitutor)2 DocumentDiff (de.tblsoft.solr.pipeline.bean.DocumentDiff)1 FieldDiff (de.tblsoft.solr.pipeline.bean.FieldDiff)1 BufferedWriter (java.io.BufferedWriter)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1 CSVFormat (org.apache.commons.csv.CSVFormat)1 CSVPrinter (org.apache.commons.csv.CSVPrinter)1