Search in sources :

Example 16 with Field

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

the class BlacklistFieldFilter method document.

@Override
public void document(Document document) {
    Document newDocument = new Document();
    for (Field field : document.getFields()) {
        if (fields == null || fields.contains(field.getName())) {
            List<String> newValues = new ArrayList<String>();
            for (String value : field.getValues()) {
                if (!topicValues.get(topic).contains(value)) {
                    newValues.add(value);
                }
            }
            newDocument.setField(field.getName(), newValues);
        } else {
            newDocument.setField(field.getName(), field.getValues());
        }
    }
    super.document(newDocument);
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field) ArrayList(java.util.ArrayList) Document(de.tblsoft.solr.pipeline.bean.Document)

Example 17 with Field

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

the class BlacklistTopicFilter method document.

@Override
public void document(Document document) {
    boolean blacklist = false;
    Field topic = document.getField(fieldTopic);
    Field value = document.getField(fieldValue);
    if (topic != null && value != null) {
        if (topicValues.containsKey(topic.getValue())) {
            blacklist = topicValues.get(topic.getValue()).contains(value.getValue().toLowerCase());
        }
    }
    if (!blacklist) {
        super.document(document);
    }
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field)

Example 18 with Field

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

the class TopicMergeFilter method mergeDocuments.

protected Document mergeDocuments(Document doc1, Document doc2) {
    Map<String, HashSet<String>> mergedFields = new HashMap<String, HashSet<String>>();
    for (Field field : doc1.getFields()) {
        if (field.getValues() != null) {
            mergedFields.put(field.getName(), new HashSet<String>(field.getValues()));
        }
    }
    for (Field field : doc2.getFields()) {
        if (mergedFields.containsKey(field.getName())) {
            if (field.getValues() != null) {
                mergedFields.get(field.getName()).addAll(field.getValues());
            }
        }
    }
    Document mergedDoc = new Document();
    for (Map.Entry<String, HashSet<String>> entry : mergedFields.entrySet()) {
        Field mergedField = new Field(entry.getKey(), new ArrayList<String>(entry.getValue()));
        mergedDoc.addField(mergedField);
    }
    return mergedDoc;
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field) Document(de.tblsoft.solr.pipeline.bean.Document)

Example 19 with Field

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

the class KeyValueSplitterFilter method processKeyValue.

Field processKeyValue(String keyValue) {
    if (Strings.isNullOrEmpty(keyValue)) {
        return null;
    }
    String[] splittedValue = keyValue.split(Pattern.quote(keyValueDelimiter));
    if (splittedValue.length != 2) {
        return null;
    }
    String key = keyPrefix + splittedValue[0];
    if (normalizeKey) {
        key = DocumentUtils.normalizeFieldKey(key);
    }
    Field field = new Field(key, splittedValue[1]);
    return field;
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field)

Example 20 with Field

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

the class KeyValueSplitterFilter method document.

@Override
public void document(Document document) {
    List<String> values = document.getFieldValues(fieldName, new ArrayList<String>());
    for (String value : values) {
        String[] splittedValues = value.split(Pattern.quote(delimiter));
        for (String splittedValue : splittedValues) {
            Field field = processKeyValue(splittedValue);
            if (field != null) {
                document.addField(field);
            }
        }
    }
    super.document(document);
}
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