public SolrSearchDocument() { this(new SolrDocument()); }
public SolrSearchDocument() { this(new SolrDocument()); }
/** * @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; }
@Override protected SearchDocument copyDocument(SearchDocument doc) { SolrDocument document = ((SolrSearchDocument)doc).getDocument(); SolrDocument newDocument = new SolrDocument(); newDocument.putAll(document); return new SolrSearchDocument(newDocument); }
@Override protected SearchDocument copyDocument(SearchDocument doc) { SolrDocument document = ((SolrSearchDocument)doc).getDocument(); SolrDocument newDocument = new SolrDocument(); newDocument.putAll(document); return new SolrSearchDocument(newDocument); }
private void append(SolrDocumentList results, ScoreDoc[] more, Set<Integer> alreadyFound, Map<String,SchemaField> fields, Map<String,Object> extraFields, float scoreCutoff, IndexReader reader, boolean includeScore) throws IOException { for (ScoreDoc hit : more) { if (alreadyFound.contains(hit.doc)) { continue; } Document doc = reader.document(hit.doc); SolrDocument sdoc = new SolrDocument(); for (String fieldname : fields.keySet()) { SchemaField sf = fields.get(fieldname); if (sf.stored()) { sdoc.addField(fieldname, doc.get(fieldname)); } } for (String extraField : extraFields.keySet()) { sdoc.addField(extraField, extraFields.get(extraField)); } if (includeScore) { sdoc.addField("score", hit.score); } results.add(sdoc); alreadyFound.add(hit.doc); } } public class PairComparable implements Comparator<Pair> {
private void append(SolrDocumentList results, ScoreDoc[] more, Set<Integer> alreadyFound, Map<String,SchemaField> fields, Map<String,Object> extraFields, float scoreCutoff, IndexReader reader, boolean includeScore) throws IOException { for (ScoreDoc hit : more) { if (alreadyFound.contains(hit.doc)) { continue; } Document doc = reader.document(hit.doc); SolrDocument sdoc = new SolrDocument(); for (String fieldname : fields.keySet()) { SchemaField sf = fields.get(fieldname); if (sf.stored()) { sdoc.addField(fieldname, doc.get(fieldname)); } } for (String extraField : extraFields.keySet()) { sdoc.addField(extraField, extraFields.get(extraField)); } if (includeScore) { sdoc.addField("score", hit.score); } results.add(sdoc); alreadyFound.add(hit.doc); } } public class PairComparable implements Comparator<Pair> {
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; }
@Override public T convert(Map<String, ?> source) { if (source == null) { return null; } SolrDocument document = new SolrDocument(); document.putAll(source); if (source instanceof SolrDocument && ((SolrDocument) source).hasChildDocuments()) { document.addChildDocuments(((SolrDocument) source).getChildDocuments()); } return documentObjectBinder.getBean(clazz, document); }
public SolrDocument getDoc(Document doc) { SolrDocument solrDoc = new SolrDocument(); for (Fieldable f : (List<Fieldable>) doc.getFields()) { String fieldName = f.name(); if (returnFields != null && !returnFields.contains(fieldName)) continue; FieldType ft = schema.getFieldTypeNoEx(fieldName); Object val; if (ft == null) { // handle fields not in the schema if (f.isBinary()) val = f.binaryValue(); else val = f.stringValue(); } else { try { if (useFieldObjects && KNOWN_TYPES.contains(ft.getClass())) { val = ft.toObject(f); } else { val = ft.toExternal(f); } } catch (Exception e) { // There is a chance of the underlying field not really matching the // actual field type . So ,it can throw exception LOG.warn("Error reading a field from document : " + solrDoc, e); //if it happens log it and continue continue; } } solrDoc.addField(fieldName, val); } return solrDoc; }
@Override public SolrDocumentList getResults() { SolrDocumentList results = new SolrDocumentList(); for (int i = 0; i < 1000; i++) { results.add(new SolrDocument()); } results.setNumFound(1000); counter++; return results; }
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; }
SolrDocument solrDocument = new SolrDocument(); documentBuilder.loadStoredFields(solrDocument, luceneDocument); documentList.add(solrDocument);
/** * @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; }
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; }
SolrDocument doc = new SolrDocument();
SolrDocument doc = new SolrDocument(); db.loadStoredFields(doc, luceneDoc);