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):
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:
id,name,popularity 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"?> <response> <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> </lst> </lst> <result name="response" numFound="2" start="0"> <doc> <str name="id">SP2514N</str> <str name="name">Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133</str> <int name="popularity">6</int> </doc> <doc> <str name="id">6H500F0</str> <str name="name">Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300</str> <int name="popularity">6</int> </doc> </result> </response>
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 post is also available in: Polish