Search in sources :

Example 1 with DocumentDiff

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

the class DocumentDifferTest method testCreateField.

@Test
public void testCreateField() {
    Document document1 = DocumentBuilder.document().field("foo", "bar").create();
    Document document2 = DocumentBuilder.document().field("foo", "bar").field("change", "new").create();
    DocumentDiff diff = DocumentDiffer.compare(document1, document2);
    Assert.assertEquals(1, diff.getFieldDiffs().size());
    Assert.assertEquals(FieldDiff.DiffType.CREATE, diff.getFieldDiffs().get(0).getDiffType());
}
Also used : DocumentDiff(de.tblsoft.solr.pipeline.bean.DocumentDiff) Document(de.tblsoft.solr.pipeline.bean.Document) Test(org.junit.Test)

Example 2 with DocumentDiff

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

the class DocumentDifferTest method testDeleteField.

@Test
public void testDeleteField() {
    Document document1 = DocumentBuilder.document().field("foo", "bar").field("change", "old").create();
    Document document2 = DocumentBuilder.document().field("foo", "bar").create();
    DocumentDiff diff = DocumentDiffer.compare(document1, document2);
    Assert.assertEquals(1, diff.getFieldDiffs().size());
    Assert.assertEquals(FieldDiff.DiffType.DELETE, diff.getFieldDiffs().get(0).getDiffType());
}
Also used : DocumentDiff(de.tblsoft.solr.pipeline.bean.DocumentDiff) Document(de.tblsoft.solr.pipeline.bean.Document) Test(org.junit.Test)

Example 3 with DocumentDiff

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

the class DocumentDiffer method compare.

public static DocumentDiff compare(Document d1, Document d2) {
    DocumentDiff diff = new DocumentDiff();
    for (Field field : d1.getFields()) {
        List<String> values1 = field.getValues();
        List<String> values2 = d2.getFieldValues(field.getName());
        d2.deleteField(field.getName());
        FieldDiff.DiffType changeType = getChangeType(values1, values2);
        FieldDiff fieldDiff = new FieldDiff();
        fieldDiff.setDiffType(changeType);
        if (!changeType.equals(FieldDiff.DiffType.EQUAL)) {
            fieldDiff.setOldValues(values1);
            fieldDiff.setNewValue(values2);
            diff.getFieldDiffs().add(fieldDiff);
        }
    }
    for (Field field : d2.getFields()) {
        FieldDiff fieldDiff = new FieldDiff();
        fieldDiff.setDiffType(FieldDiff.DiffType.CREATE);
        fieldDiff.setNewValue(field.getValues());
        diff.getFieldDiffs().add(fieldDiff);
    }
    return diff;
}
Also used : Field(de.tblsoft.solr.pipeline.bean.Field) DocumentDiff(de.tblsoft.solr.pipeline.bean.DocumentDiff) FieldDiff(de.tblsoft.solr.pipeline.bean.FieldDiff)

Example 4 with DocumentDiff

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

the class DocumentDifferTest method testDiffDocuments.

@Test
public void testDiffDocuments() {
    Document document1 = DocumentBuilder.document().field("foo", "bar").field("change", "old").create();
    Document document2 = DocumentBuilder.document().field("foo", "bar").field("change", "new").create();
    DocumentDiff diff = DocumentDiffer.compare(document1, document2);
    Assert.assertEquals(1, diff.getFieldDiffs().size());
    Assert.assertEquals(FieldDiff.DiffType.DIFF, diff.getFieldDiffs().get(0).getDiffType());
}
Also used : DocumentDiff(de.tblsoft.solr.pipeline.bean.DocumentDiff) Document(de.tblsoft.solr.pipeline.bean.Document) Test(org.junit.Test)

Example 5 with DocumentDiff

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

the class DocumentDifferTest method testEqualDocuments.

@Test
public void testEqualDocuments() {
    Document document1 = DocumentBuilder.document().field("foo", "bar").create();
    Document document2 = DocumentBuilder.document().field("foo", "bar").create();
    DocumentDiff diff = DocumentDiffer.compare(document1, document2);
    Assert.assertEquals(0, diff.getFieldDiffs().size());
}
Also used : DocumentDiff(de.tblsoft.solr.pipeline.bean.DocumentDiff) Document(de.tblsoft.solr.pipeline.bean.Document) Test(org.junit.Test)

Aggregations

DocumentDiff (de.tblsoft.solr.pipeline.bean.DocumentDiff)5 Document (de.tblsoft.solr.pipeline.bean.Document)4 Test (org.junit.Test)4 Field (de.tblsoft.solr.pipeline.bean.Field)1 FieldDiff (de.tblsoft.solr.pipeline.bean.FieldDiff)1