In the process of handling a type of web service request, I need to create a 
series of documents for indexing. They differ by only a couple of field values, 
but share quite a few others.  I would like to clone SolrInputDocument and 
adjust a couple of fields, index that, lather, rinse, repeat.

However, org.apache.solr.common.SolrInputDocument (branch_3x) does  not 
implement Cloneable, override clone() to make a deep-copy etc. Also observed by 
looking at the source code is the fact that SolrInputDocument keeps all fields 
in a LinkedHashMap, and also exposes a Map interface.

So, does this sound like a workable idea?  I define all my fields in a 
Map<String, SolrInputField> for the first document, and then tweak and re-use 
it. E.g.:

Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
Map<String, SolrInputField> fields = ...;  //Set up fields for 1st document

SolrInputDocument doc = new SolrInputDocument();
doc.putAll(fields);
docs.add(doc);

//Update values for fields (keys) a and b in fields Map.

doc = new SolrInputDocument();
doc.putAll(fields);
docs.add(doc);

//Update values for fields (keys) a and b in fields Map.

doc = new SolrInputDocument();
doc.putAll(fields);
docs.add(doc);

and so forth. Then:

SolrServer solrServer = getSolrServer();
solrServer.add(docs);
solrServer.commit();

Map.putAll "Copies all of the mappings from the specified map to this map", so 
each document will have its own copy of the fields. I will, or course, have to 
have map values of SolrInputField and instantiate those etc.  Perhaps this is 
not worth the effort and I should be be satisfied repeating the same 
doc.addField() method calls.

Thanks,

Jeff
--
Jeff Schmidt
535 Consulting
j...@535consulting.com
(650) 423-1068
http://www.535consulting.com






Reply via email to