I set up a Solr Server on a TomCat-Servlet. In my Index there are about 610.000 Documents with several fields. My schema.xml:
<field name="ID" type="myText" indexed="true" stored="true" required="true" />
<field name="text" type="myText" indexed="true" stored="false" multiValued="true" />
<dynamicField name="AT*" type="text_general" indexed="true" stored="true" multiValued="true" />
To search the Index with a given String (might be from another system) I created a little JavaProgram
class SolrjTest
{
public static void main(String[] args) throws IOException
{
SolrjTest solrj = new SolrjTest();
solrj.query(args[0]);
}
public void query(String q) throws IOException
{
CommonsHttpSolrServer server = null;
String uuid = null;
boolean flag = true;
while(flag==true)
{
uuid = UUID.randomUUID().toString();
File f = new File("E:/dw-solr/tomcat-solr/bin/solr/data/SearchResult/"+uuid+".txt");
if(!f.exists()){
flag = false;
}
}
try
{
server = new CommonsHttpSolrServer("http://localhost:8080/solr");
}
catch(Exception e)
{
e.printStackTrace();
}
SolrQuery query = new SolrQuery();
query.setQuery(q);
FileWriter fw = new FileWriter("E:/dw-solr/tomcat-solr/bin/solr/data/SearchResult/"+uuid+".txt");
try
{
QueryResponse qr = server.query(query);
SolrDocumentList sdl = qr.getResults();
Object[] o = new Object[sdl.size()];
o = sdl.toArray();
for (int i = 0; i < o.length; i++) {
System.out.println(o[i].toString());
fw.write(o[i].toString() + "\n");
}
fw.flush();
fw.close();
System.out.println("finished");
}
catch (SolrServerException e)
{
e.printStackTrace();
}
}
And the results are saved in files. The problem is, that the format of the data is really strange. It looks like:
"SolrDocument[{ID=0000000, AT_anyName=[anyValue, multiValue, justMoreValue], AT_anyName2=[Normal,Normal, Normal], AT_mightbeanothername=[couldbealoooooooooooooooongvalue, andanotherone, andanotherone]muchMoreStuff...about 20 - can differ from ID to ID}]"
What I want to have, is a clear XML-format for this data. So I save it as a XML-file and send it back to the other System. The problem is, that the Method SolrDocumentList sdl = qr.getResults(); return the result as shown above. As I posted before, I have dynamicFields so stuff get really complicated (at least for me :-/ ). Is there any solution, how I can change the format to a plain, clear XML-format?
Thanks a lot for any help.
Best regards
Response Writers is used to generate different formats of the search responses.By default it returns the XML response. By sending the HTTP request you can get response in xml format.