Search in sources :

Example 41 with Document

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

the class TopicAggregationFilter method document.

@Override
public void document(Document document) {
    for (AggregationId idField : idFields) {
        String docId = idField.buildId(document);
        if (docId != null) {
            putTopicValueAsField(document);
            if (!docs.containsKey(docId)) {
                // create
                docs.put(docId, document);
            } else {
                // merge
                Document oldDoc = docs.get(docId);
                Document mergedDoc = mergeDocuments(oldDoc, document);
                docs.put(docId, mergedDoc);
            }
            break;
        }
    }
}
Also used : Document(de.tblsoft.solr.pipeline.bean.Document)

Example 42 with Document

use of de.tblsoft.solr.pipeline.bean.Document 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 43 with Document

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

the class MappingFilter method document.

@Override
public void document(Document document) {
    Document mappedDocument;
    if (!appendFields) {
        mappedDocument = new Document();
    } else {
        mappedDocument = new Document();
        mappedDocument.getFields().addAll(document.getFields());
    }
    for (Field f : document.getFields()) {
        List<String> mappedNameList = mapping.get(f.getName());
        if (mappedNameList == null) {
            continue;
        }
        for (String mappedName : mappedNameList) {
            List<String> mappedFunctions = mappingFunctions.get(mappedName);
            if (!Strings.isNullOrEmpty(mappedName)) {
                List<String> newValues = new ArrayList<String>();
                for (String value : f.getValues()) {
                    String newValue = value;
                    for (String function : mappedFunctions) {
                        newValue = simpleMapping.executeFunction(function, newValue);
                    }
                    newValues.add(newValue);
                }
                mappedDocument.addField(mappedName, newValues);
                Field mappedField = mappedDocument.getField(mappedName);
                for (String function : mappedFunctions) {
                    simpleMapping.executeFieldFunction(function, mappedField);
                }
            }
        }
    }
    for (Map.Entry<String, String> entry : joins.entrySet()) {
        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(entry.getValue());
        mappedDocument.addField(entry.getKey(), value);
    }
    if (mappedDocument.getFields().size() != 0) {
        addMissingFields(mappedDocument);
        sortFieldsByName(mappedDocument);
        super.document(mappedDocument);
    }
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field) StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) Document(de.tblsoft.solr.pipeline.bean.Document)

Example 44 with Document

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

the class AbstractBaseTest method assertFiledNotExists.

public void assertFiledNotExists(String name) {
    if (outputDocumentList.size() == 0) {
        Assert.fail("There is no output document.");
    }
    Document document = outputDocumentList.get(0);
    Field f = document.getField(name);
    Assert.assertNull(f);
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field) Document(de.tblsoft.solr.pipeline.bean.Document)

Example 45 with Document

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

the class AbstractBaseTest method assertFiledExists.

public void assertFiledExists(String name) {
    if (outputDocumentList.size() == 0) {
        Assert.fail("There is no output document.");
    }
    Document document = outputDocumentList.get(0);
    Field f = document.getField(name);
    Assert.assertNotNull(f);
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field) Document(de.tblsoft.solr.pipeline.bean.Document)

Aggregations

Document (de.tblsoft.solr.pipeline.bean.Document)51 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 Test (org.junit.Test)9 Field (de.tblsoft.solr.pipeline.bean.Field)8 DocumentDiff (de.tblsoft.solr.pipeline.bean.DocumentDiff)4 AbstractFilterTest (de.tblsoft.solr.pipeline.test.AbstractFilterTest)4 GsonBuilder (com.google.gson.GsonBuilder)3 Match (oi.thekraken.grok.api.Match)3 AtomicLongMap (com.google.common.util.concurrent.AtomicLongMap)2 Gson (com.google.gson.Gson)2 JsonElement (com.google.gson.JsonElement)2 DocumentContext (com.jayway.jsonpath.DocumentContext)2 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)2 DocumentBuilder (de.tblsoft.solr.pipeline.bean.DocumentBuilder)2 SimpleMapping (de.tblsoft.solr.pipeline.filter.SimpleMapping)2 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2