Solr recently received another small, but worth mentioning functionality – another response format available in standard distribution – CSV response format. I decided to write a short note about it.

After compiling and building an example we need to uncomment the following line (in solrconfig.xml):

<queryResponseWriter name="csv"/>

After this we only need to start and index some data. I used the data from an example file (hd.xml).

As the functionality is really simple i decided to only test if it works 😉 After running a query like q=*:*&fl=id,name,popularity&wt=csv i got the following data:

SP2514N,Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133,6
6H500F0,Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300,6

The same query (of course, without the wt=csv parameter) will generate the following xml file:

<?xml version="1.0" encoding="UTF-8"?>
<lst name="responseHeader">
   <int name="status">0</int>
   <int name="QTime">0</int>
   <lst name="params">
      <str name="q">*:*</str>
      <str name="fl">id,name,popularity</str>
<result name="response" numFound="2" start="0">
   <str name="id">SP2514N</str>
   <str name="name">Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133</str>
   <int name="popularity">6</int>
   <str name="id">6H500F0</str>
   <str name="name">Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300</str>
   <int name="popularity">6</int>

The end

If You want a quick look at the data in the index without unnecessary details and You do not want to play with XML parsing than CSV format seems to be quite reasonable alternative. Note, however, that the new ResponseWriter will not return information like number of documents matching the query or query time. But, if you do not need such information, then You should look at the CSVResponseWriter.

This entry was posted on Tuesday, August 3rd, 2010 at 08:35 and is filed under About Solr. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.