@Override public void transform(SolrDocument doc, int docid) { doc.setField( name, docid ); } }
this.setField( name, value ); return;
/** * @param d SolrInputDocument to convert * @return a SolrDocument with the same fields and values as the SolrInputDocument */ public static SolrDocument toSolrDocument( SolrInputDocument d ) { SolrDocument doc = new SolrDocument(); for( SolrInputField field : d ) { doc.setField( field.getName(), field.getValue() ); } return doc; }
public static SolrInputDocument addOtherPropertiesToIndexedFile(String prefix, OtherMetadata otherMetadataBinary, ModelService model, SolrClient index) throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException, ParserConfigurationException, SAXException, IOException, XPathExpressionException, SolrServerException { SolrDocument solrDocument = index.getById(RodaConstants.INDEX_FILE, IdUtils.getFileId(otherMetadataBinary.getAipId(), otherMetadataBinary.getRepresentationId(), otherMetadataBinary.getFileDirectoryPath(), otherMetadataBinary.getFileId())); Binary binary = model.retrieveOtherMetadataBinary(otherMetadataBinary); Map<String, List<String>> otherProperties = MetadataFileUtils.parseBinary(binary); for (Map.Entry<String, List<String>> entry : otherProperties.entrySet()) { solrDocument.setField(prefix + entry.getKey(), entry.getValue()); } return solrDocumentToSolrInputDocument(solrDocument); }
public SolrDocument readSolrDocument(DataInputInputStream dis) throws IOException { tagByte = dis.readByte(); int size = readSize(dis); SolrDocument doc = new SolrDocument(new LinkedHashMap<>(size)); for (int i = 0; i < size; i++) { String fieldName; Object obj = readVal(dis); // could be a field name, or a child document if (obj instanceof SolrDocument) { doc.addChildDocument((SolrDocument)obj); continue; } else { fieldName = (String)obj; } Object fieldVal = readVal(dis); doc.setField(fieldName, fieldVal); } return doc; }
public SolrDocument readSolrDocument(FastInputStream dis) throws IOException { NamedList nl = (NamedList) readVal(dis); SolrDocument doc = new SolrDocument(); for (int i = 0; i < nl.size(); i++) { String name = nl.getName(i); Object val = nl.getVal(i); doc.setField(name, val); } return doc; }
private void returnFields(ResponseBuilder rb, ShardRequest sreq) { // Keep in mind that this could also be a shard in a multi-tiered system. // TODO: if a multi-tiered system, it seems like some requests // could/should bypass middlemen (like retrieving stored fields) // TODO: merge fsv to if requested if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) { boolean returnScores = (rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0; assert(sreq.responses.size() == 1); ShardResponse srsp = sreq.responses.get(0); SolrDocumentList docs = (SolrDocumentList)srsp.getSolrResponse().getResponse().get("response"); String keyFieldName = rb.req.getSchema().getUniqueKeyField().getName(); for (SolrDocument doc : docs) { Object id = doc.getFieldValue(keyFieldName); ShardDoc sdoc = rb.resultIds.get(id.toString()); if (sdoc != null) { if (returnScores && sdoc.score != null) { doc.setField("score", sdoc.score); } rb._responseDocs.set(sdoc.positionInResponse, doc); } } } }
private static SolrDocument toSolrDoc(Document doc, IndexSchema schema) { SolrDocument out = new SolrDocument(); for ( IndexableField f : doc.getFields() ) { // Make sure multivalued fields are represented as lists Object existing = out.get(f.name()); if (existing == null) { SchemaField sf = schema.getFieldOrNull(f.name()); // don't return copyField targets if (sf != null && schema.isCopyFieldTarget(sf)) continue; if (sf != null && sf.multiValued()) { List<Object> vals = new ArrayList<>(); vals.add( f ); out.setField( f.name(), vals ); } else{ out.setField( f.name(), f ); } } else { out.addField( f.name(), f ); } } return out; }
@Override public void transform(SolrDocument doc, int docid) throws IOException { Query query = context.query; SimpleJsonByQueryExtractor extractor = new SimpleJsonByQueryExtractor(); try { IndexSchema schema = context.req.getSchema(); for (String fieldName : doc.getFieldNames()) { FieldType ft = schema.getFieldOrNull(fieldName).getType(); if (ft instanceof ExtendedJsonField) { String sirenField = (String) doc.getFieldValue(fieldName); String json = extractor.extractAsString(sirenField, query); if (json == null) { // query doesn't contain variables, no transformation is necessary continue; } doc.setField(fieldName, json); } } } catch (ProjectionException e) { throw new IOException(String.format( "Problem while projecting (extracting variables from matched document id %s", doc.getFieldValue("id")), e); } }
public SolrDocument readSolrDocument(DataInputInputStream dis) throws IOException { tagByte = dis.readByte(); int size = readSize(dis); SolrDocument doc = new SolrDocument(); for (int i = 0; i < size; i++) { String fieldName; Object obj = readVal(dis); // could be a field name, or a child document if (obj instanceof SolrDocument) { doc.addChildDocument((SolrDocument)obj); continue; } else { fieldName = (String)obj; } Object fieldVal = readVal(dis); doc.setField(fieldName, fieldVal); } return doc; }
/** * @param d SolrInputDocument to convert * @return a SolrDocument with the same fields and values as the SolrInputDocument */ public static SolrDocument toSolrDocument(SolrInputDocument d) { SolrDocument doc = new SolrDocument(); for (SolrInputField field : d) { doc.setField(field.getName(), field.getValue()); } if (d.getChildDocuments() != null) { for (SolrInputDocument in : d.getChildDocuments()) { doc.addChildDocument(toSolrDocument(in)); } } return doc; }
/** * Converts a lucene document to a solr document. * * @param schema the index schema * @param luceneDoc the lucene document * @return solr document */ public SolrDocument toSolrDoc(IndexSchema schema, Document luceneDoc) { SolrDocument solrDoc = new SolrDocument(); luceneDoc.forEach(it -> solrDoc.addField(it.name(), schema.getField(it.name()).getType().toObject(it))); for (String field : solrDoc.getFieldNames()) { Object value = solrDoc.getFieldValue(field); if (value instanceof ByteBuffer) { solrDoc.setField(field, ((ByteBuffer) value).array()); } } return solrDoc; }
private SolrDocument solrDocumentWithOutTimeSeriesFunctionResults(boolean dataShouldReturned, boolean dataAsJson, ChronixTimeSeries timeSeries) { SolrDocument doc = new SolrDocument(); //add the join key doc.put(ChronixQueryParams.JOIN_KEY, timeSeries.getJoinKey()); for (Map.Entry<String, Object> entry : (Set<Map.Entry<String, Object>>) timeSeries.getAttributes().entrySet()) { doc.addField(entry.getKey(), entry.getValue()); } //add the metric field as it is not stored in the getAttributes doc.addField(Schema.NAME, timeSeries.getName()); doc.addField(Schema.TYPE, timeSeries.getType()); //TODO: Fix this. It is expensive to calculate this based on the points. This is already stored. doc.addField(Schema.START, timeSeries.getStart()); doc.addField(Schema.END, timeSeries.getEnd()); if (dataShouldReturned) { //ensure that the returned data is sorted timeSeries.sort(); //data should returned serialized as json if (dataAsJson) { doc.setField(ChronixQueryParams.DATA_AS_JSON, timeSeries.dataAsJson()); } else { doc.addField(Schema.DATA, timeSeries.dataAsBlob()); } } return doc; }