> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
> Of Yonik Seeley
> Sent: Monday, 17 December 2007 4:44 PM
> To: [email protected]
> Subject: Re: retrieve lucene "doc id"
>
> On Dec 16, 2007 11:40 PM, Ben Incani
> <[EMAIL PROTECTED]> wrote:
> > how do I retrieve the lucene "doc id" in a query?
>
> Currently that's not doable... if it was though, it would be
> a slightly dangerous feature since internal ids are transient.
> Can you explain a little more about what you are trying to do?
>
> -Yonik
>
Hi Yonik,
I have converted to using the Solr search interface and I am trying to
retrieve documents from a list of search results (where previously I had
used the doc id directly from the lucene query results) and the solr id
I have got currently indexed is unfortunately configured not be unique!
I do realise that lucene internal ids are transient, but for a read-only
requests (that are not cached) should be ok.
i have hacked org.apache.solr.request.XMLWriter.writeDoc to do a
writeInt("docId", docId).
**** code snippet ****
SolrServer server = new CommonsHttpSolrServer(solrURL);
Map<String,String> params = new HashMap<String,String>();
params.put("q", searchQuery);
params.put("rows", "20");
MapSolrParams solrParams = new MapSolrParams(params);
QueryResponse response = server.query(solrParams);
SolrDocumentList docs = response.getResults();
ArrayList<HashMap> hitsList = new ArrayList<HashMap>();
for (int i = 0; i < docs.getNumFound(); i++) {
HashMap<String,Object> resultMap = new HashMap<String,Object>();
SolrDocument doc = (SolrDocument)docs.get(i);
resultMap.put("id", doc.getFieldValue("docId"));
for(int j=0; j<resultFields.length; j++) {
String fieldName = (String)resultFields[j];
resultMap.put(fieldName, doc.getFieldValue(fieldName));
}
hitsList.add(resultMap);
}
**** code snippet ****