This is the archive for June 2008

Walking a solr index

Here's a quick snippet of code to walk a solr index, for use with localsolr.
Running this requires obviously changing the code to point to your solr instance, and
also to add all the solr libraries dependencies to your class path.

This is probably going to leave my google adsense showing java for the next 2 months.
Yes google ad's those things that you would hopefully be clicking on if you weren't using
an rss reader :-( oh well, I guess I was never destined to become rich.... :-)

import java.util.Iterator;
import java.util.Map.Entry;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.lucene.document.Document;
import org.apache.solr.client.solrj.util.ClientUtils;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.update.DocumentBuilder;
import org.xml.sax.SAXException;

public class Foo {

SolrConfig cfg;
SolrCore core;
String solrBase = "/Users/pjaol/tmp/solr/tmp/apache-tomcat-5.5.26/solr/";
String solrDataDir = solrBase+"/core0/data/"; // your probably not using multicore so you'll have /data/
String solrSchema = solrBase+"/core0/conf/schema.xml";
String solrConfig = solrBase+"/core0/conf/solrconfig.xml";
public static void main(String[] args) {
Foo f = new Foo();
try {
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
} catch (SAXException e) {
// TODO Auto-generated catch block


public void init() throws ParserConfigurationException, IOException, SAXException{
cfg = new SolrConfig(solrBase,"foo", new FileInputStream(solrConfig));
core = new SolrCore(null,solrDataDir , cfg,
new IndexSchema(cfg, solrSchema, null));

SolrIndexSearcher searcher = core.newSearcher("foo");
int mxdocs = searcher.maxDoc();

BufferedWriter writer = new BufferedWriter(new FileWriter("index.xml"));

for (int i = 0; i< mxdocs; i++){
Document luceneDoc = searcher.doc(i);

SolrDocument sdoc = new SolrDocument();
DocumentBuilder db = new DocumentBuilder(searcher.getSchema());
sdoc = db.loadStoredFields(sdoc, luceneDoc);

Iterator<Entry<String, Object>> it = sdoc.iterator();
SolrInputDocument sidoc = new SolrInputDocument();
while (it.hasNext()){
Entry<String, Object> et =;
if (et.getKey().startsWith("_local")) {
sidoc.addField(et.getKey(), et.getValue());
ClientUtils.writeXML(sidoc, writer);


This will create an index.xml file you can use solr's post jar or sh files to reindex back on solr.

Scooters not doing so good

Scooter my 2 year old dachshund hasn't been feeling well recently.
As a puppy he had a lot of digestive problems, every couple of months
he used get diarrhea pretty bad, and we kept going back to the vet.
Each time we got a temporary solution, so I did some investigating and changed
his diet to Royal Canin Dachshund specific food, and it worked miracles.
He's been incident free for the past year.

That is until Wednesday, where it started with diarrhea again, but then Friday, it
was really bad, as he started vomiting as well, the only thing to change was I got
a new bag of his food. I contacted the store, who said they've had no issues, Friday
I contacted Royal Canin, who said the same thing, but recommended that to get
a sample for testing. I was actually impressed how personal they were and willing
to respond and take the matter seriously.

So I took scooter to the vet Friday, and it shuck me a lot, the vet said he was concerned
about the number of incidents that scooter had this problem in the past, and was concerned
that this was a chronic issue. Scooter was dehydrated, so they gave him fluids under the skin,
something to try and stop the vomiting, and then Metronidazole tablets to take home.

The vet said if it continues or reoccurs, he wants to test him for pancreatitis and IBS.
Both of which threw me, I was never really expecting him to have some thing that could be chronic.
He's improving slowly, he's still sick and he wasn't able to control anything, today though he didn't
throw up and there were no accidents. I've spent the day looking after him and trying to clean
up the apartment. Poor little guy, I've got to do all I can to get him back on track.