use of de.tblsoft.solr.pipeline.bean.Document in project solr-cmd-utils by tblsoft.
the class DictionaryNormalizationFilter method end.
@Override
public void end() {
List<String> sortedTokens = new ArrayList<String>(tokens);
Collections.sort(sortedTokens);
for (String token : sortedTokens) {
Document document = new Document();
document.setField("token", token);
super.document(document);
}
super.end();
}
use of de.tblsoft.solr.pipeline.bean.Document in project solr-cmd-utils by tblsoft.
the class ElasticWriter method procesBuffer.
void procesBuffer() {
try {
StringBuilder bulkRequest = new StringBuilder();
for (Document document : buffer) {
Map<String, Object> jsonDocument = mapToJson(document, detectNumberValues);
if (jsonDocument.isEmpty()) {
continue;
}
String id;
if (Strings.isStringEmpty(idField)) {
id = UUID.randomUUID().toString();
} else {
id = document.getFieldValue(idField);
}
String index = ElasticHelper.getIndexFromUrl(location);
String type = ElasticHelper.getTypeFromUrl(location);
String bulkMethod = createBulkMethod("index", index, type, id);
String json = gson.toJson(jsonDocument);
bulkRequest.append(bulkMethod).append(" \n");
bulkRequest.append(json).append(" \n");
}
String bulkUrl = ElasticHelper.getBulkUrl(location);
HTTPHelper.post(bulkUrl, bulkRequest.toString(), "application/json");
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
use of de.tblsoft.solr.pipeline.bean.Document in project solr-cmd-utils by tblsoft.
the class ElasticWriter method mapToJsonString.
public static String mapToJsonString(List<Document> documentList, boolean detectNumberValues) {
List<Map<String, Object>> documentMap = new ArrayList<Map<String, Object>>();
for (Document document : documentList) {
documentMap.add(mapToJson(document, detectNumberValues));
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(documentMap);
return json;
}
use of de.tblsoft.solr.pipeline.bean.Document in project solr-cmd-utils by tblsoft.
the class AggregationCountFilter method end.
@Override
public void end() {
for (Map.Entry<String, AtomicLongMap<String>> entry : aggregation.entrySet()) {
String fieldName = entry.getKey();
AtomicLongMap<String> fieldValue = entry.getValue();
for (Map.Entry<String, Long> fieldValueEntry : fieldValue.asMap().entrySet()) {
String value = fieldValueEntry.getKey();
Long count = fieldValueEntry.getValue();
Document document = new Document();
document.setField("value", value);
document.setField("count", count);
document.setField("type", fieldName);
super.document(document);
}
}
super.end();
}
use of de.tblsoft.solr.pipeline.bean.Document 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);
}
Aggregations