Search in sources :

Example 21 with Field

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

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

the class DocumentComparator method compare.

public int compare(Document first, Document second) {
    if (first == null && second == null) {
        return 0;
    }
    if (first == null) {
        return -1;
    }
    if (second == null) {
        return 1;
    }
    Field firstField = first.getField(fieldName);
    Field secondField = second.getField(fieldName);
    if (firstField == null && secondField == null) {
        return 0;
    }
    if (firstField == null) {
        return -1;
    }
    if (secondField == null) {
        return 1;
    }
    String firstFieldValue = firstField.getValue();
    String secondFieldValue = secondField.getValue();
    if (firstFieldValue == null && secondFieldValue == null) {
        return 0;
    }
    if (firstFieldValue == null) {
        return -1;
    }
    if (secondFieldValue == null) {
        return 1;
    }
    return firstFieldValue.compareTo(secondFieldValue);
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field)

Example 23 with Field

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

use of de.tblsoft.solr.pipeline.bean.Field 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)

Example 25 with Field

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

the class CompoundWordFilterTest method testGartentor.

@Test
@Ignore
public void testGartentor() {
    configure();
    document(DocumentBuilder.document().field("noun", "gartentor").create(), DocumentBuilder.document().field("noun", "garten").create(), DocumentBuilder.document().field("noun", "tor").create());
    Field d = outputDocumentList.get(0).getField("tokenized");
    assertFiledList("tokenized", "garten", "tor");
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field) Ignore(org.junit.Ignore) AbstractFilterTest(de.tblsoft.solr.pipeline.test.AbstractFilterTest) Test(org.junit.Test)

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