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;
}
}
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations