final String latestDateValue = df.format(lastSolrDocument.get(dateField)); final String newCursorMark = response.getNextCursorMark();
protected static void reformatComments(SolrDocument solrDocument, Map<String, Object> document) { // Make sure comments are in the proper format @SuppressWarnings("unchecked") List<String> commentStrs = (List<String>) solrDocument.get(COMMENTS_FIELD); if (commentStrs != null) { try { List<AlertComment> comments = new ArrayList<>(); for (String commentStr : commentStrs) { comments.add(new AlertComment(commentStr)); } document.put(COMMENTS_FIELD, comments.stream().map(AlertComment::asMap).collect(Collectors.toList())); } catch (ParseException e) { throw new IllegalStateException("Unable to parse comment", e); } } }
@Override public String getResource() { return (String)doc.get(SearchFields.URI_FIELD_NAME); }
@Override public String getId() { return (String)doc.get(SearchFields.ID_FIELD_NAME); }
@Override public String getContext() { return (String)doc.get(SearchFields.CONTEXT_FIELD_NAME); }
@Override public String apply(SolrDocument doc) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < involvedFields.length; i++) { String field = involvedFields[i]; sb.append(doc.get(field.trim())); if (i < involvedFields.length - 1) { sb.append('-'); } } return sb.toString(); }
@Override public boolean hasProperty(String name, String value) { List<String> fieldValues = asStringList(doc.get(name)); if (fieldValues != null) { for (String fieldValue : fieldValues) { if (value.equals(fieldValue)) { return true; } } } return false; }
/** * Extract koulutus alkamis pvm (min/max) information from solr document. * * @param koulutusDoc * @param perustieto */ private void createKoulutuksenAlkamisPvm(SolrDocument koulutusDoc, KoulutusPerustieto perustieto) { perustieto.setKoulutuksenAlkamisPvmMin((Date) koulutusDoc.get(SolrFields.Koulutus.KOULUTUALKAMISPVM_MIN)); perustieto.setKoulutuksenAlkamisPvmMax((Date) koulutusDoc.get(SolrFields.Koulutus.KOULUTUALKAMISPVM_MAX)); }
@Override public boolean hasProperty(String name, String value) { List<String> fieldValues = asStringList(doc.get(name)); if (fieldValues != null) { for (String fieldValue : fieldValues) { if (value.equals(fieldValue)) { return true; } } } return false; }
@Override public float getScore() { Number s = ((Number)doc.getDocument().get("score")); return (s != null) ? s.floatValue() : 0.0f; }
@Override public float getScore() { Number s = ((Number)doc.getDocument().get("score")); return (s != null) ? s.floatValue() : 0.0f; }
/** * 将solr的document封装进MapWritable里面 * @param doc 转换的solr document * @param value MapWritable */ public void collect(SolrDocument doc,MapWritable value){ for (String col : cols) { Object vObj = doc.get(col); Writable v = (vObj == null) ? NullWritable.get() : new Text(vObj.toString()); value.put(new Text(col), v); } }
@Override public Pair<DocumentReference, String> next() { SolrDocument result = getResults().get(index++); DocumentReference documentReference = this.solrDocumentReferenceResolver.resolve(result); String version = (String) result.get(FieldUtils.VERSION); return new ImmutablePair<DocumentReference, String>(documentReference, version); }
private String getFieldStringValue(SolrDocument solrDocument, String fieldName) { Object field = solrDocument.get(fieldName); if (field instanceof Field) { return ((Field) field).stringValue(); } else if (field instanceof IndexableField) { return ((IndexableField) field).stringValue(); } return field != null ? field.toString() : null; }
@Override public double getDistance() { Number s = ((Number)doc.getDocument().get(SolrIndex.DISTANCE_FIELD)); return (s != null) ? GeoUnits.fromKilometres(s.doubleValue(), units) : Double.NaN; } }
@Override public double getDistance() { Number s = ((Number)doc.getDocument().get(SolrIndex.DISTANCE_FIELD)); return (s != null) ? GeoUnits.fromKilometres(s.doubleValue(), units) : Double.NaN; } }
private Number getFieldNumberValue(SolrDocument solrDocument, String fieldName) { Object field = solrDocument.get(fieldName); if (field instanceof Field) { return ((Field) field).numericValue(); } else if (field instanceof IndexableField) { return ((IndexableField) field).numericValue(); } return field != null ? (Number) field : null; } }
@Override public DIPFile fromSolrDocument(SolrDocument doc, List<String> fieldsToReturn) throws GenericException { DIPFile file = super.fromSolrDocument(doc, fieldsToReturn); file.setDipId(SolrUtils.objectToString(doc.get(RodaConstants.DIPFILE_DIP_ID), null)); file.setPath(SolrUtils.objectToListString(doc.get(RodaConstants.DIPFILE_PATH))); file.setAncestorsUUIDs(SolrUtils.objectToListString(doc.get(RodaConstants.DIPFILE_ANCESTORS_UUIDS))); file.setDirectory(SolrUtils.objectToBoolean(doc.get(RodaConstants.DIPFILE_IS_DIRECTORY), Boolean.FALSE)); file.setStoragePath(SolrUtils.objectToString(doc.get(RodaConstants.DIPFILE_STORAGE_PATH), null)); file.setSize(SolrUtils.objectToLong(doc.get(RodaConstants.DIPFILE_SIZE), 0L)); return file; }
void doQuery(String expectedDocs, String... queryParams) throws Exception { Set<String> expectedIds = new HashSet<>( StrUtils.splitSmart(expectedDocs, ",", true) ); QueryResponse rsp = cloudClient.query(params(queryParams)); Set<String> obtainedIds = new HashSet<>(); for (SolrDocument doc : rsp.getResults()) { obtainedIds.add((String) doc.get("id")); } assertEquals(expectedIds, obtainedIds); }
/** * @param raw * @return The estimated country_code */ public String countryCode(String raw){ try { QueryResponse qres = this.geoindex.query(constructQuery(raw)); SolrDocumentList res = qres.getResults(); return (String) res.get(0).get("country_code"); } catch (SolrServerException e) { } return null; }