47 |
47 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
48 |
48 |
import org.apache.commons.logging.Log;
|
49 |
49 |
import org.apache.commons.logging.LogFactory;
|
|
50 |
import org.apache.solr.client.solrj.SolrQuery;
|
50 |
51 |
import org.apache.solr.client.solrj.SolrServer;
|
51 |
52 |
import org.apache.solr.client.solrj.SolrServerException;
|
|
53 |
import org.apache.solr.client.solrj.response.QueryResponse;
|
52 |
54 |
import org.apache.solr.client.solrj.response.UpdateResponse;
|
|
55 |
import org.apache.solr.common.SolrDocument;
|
|
56 |
import org.apache.solr.common.SolrDocumentList;
|
53 |
57 |
import org.apache.solr.common.SolrInputDocument;
|
|
58 |
import org.apache.solr.common.util.NamedList;
|
54 |
59 |
import org.dataone.cn.indexer.XMLNamespaceConfig;
|
55 |
60 |
import org.dataone.cn.indexer.parser.IDocumentSubprocessor;
|
56 |
61 |
import org.dataone.cn.indexer.parser.SolrField;
|
... | ... | |
61 |
66 |
import org.dataone.service.util.TypeMarshaller;
|
62 |
67 |
import org.jibx.runtime.JiBXException;
|
63 |
68 |
import org.w3c.dom.Document;
|
|
69 |
import org.w3c.dom.NameList;
|
64 |
70 |
import org.xml.sax.SAXException;
|
65 |
71 |
|
66 |
72 |
/**
|
... | ... | |
70 |
76 |
*/
|
71 |
77 |
public class SolrIndex {
|
72 |
78 |
|
|
79 |
public static final String ID = "id";
|
|
80 |
private static final String IDQUERY = ID+":*";
|
73 |
81 |
private List<IDocumentSubprocessor> subprocessors = null;
|
74 |
82 |
private SolrServer solrServer = null;
|
75 |
83 |
private XMLNamespaceConfig xmlNamespaceConfig = null;
|
... | ... | |
372 |
380 |
* Get the solrServer
|
373 |
381 |
* @return
|
374 |
382 |
*/
|
375 |
|
SolrServer getSolrServer() {
|
|
383 |
public SolrServer getSolrServer() {
|
376 |
384 |
return solrServer;
|
377 |
385 |
}
|
378 |
386 |
|
379 |
387 |
/**
|
380 |
|
* Set the solrServer. This method is only for setting a test solr server in the junit test.
|
|
388 |
* Set the solrServer.
|
381 |
389 |
* @param solrServer
|
382 |
390 |
*/
|
383 |
|
void setSolrServer(SolrServer solrServer) {
|
|
391 |
public void setSolrServer(SolrServer solrServer) {
|
384 |
392 |
this.solrServer = solrServer;
|
385 |
393 |
}
|
|
394 |
|
|
395 |
/**
|
|
396 |
* Get all indexed ids in the solr server.
|
|
397 |
* @return
|
|
398 |
* @throws SolrServerException
|
|
399 |
*/
|
|
400 |
public List<String> getSolrIds() throws SolrServerException {
|
|
401 |
List<String> list = new ArrayList<String>();
|
|
402 |
SolrQuery query = new SolrQuery(IDQUERY);
|
|
403 |
query.setRows(Integer.MAX_VALUE);
|
|
404 |
query.setFields(ID);
|
|
405 |
QueryResponse response = solrServer.query(query);
|
|
406 |
SolrDocumentList docs = response.getResults();
|
|
407 |
if(docs != null) {
|
|
408 |
for(SolrDocument doc :docs) {
|
|
409 |
String identifier = (String)doc.getFieldValue(ID);
|
|
410 |
//System.out.println("======================== "+identifier);
|
|
411 |
list.add(identifier);
|
|
412 |
}
|
|
413 |
}
|
|
414 |
return list;
|
|
415 |
}
|
386 |
416 |
}
|
Add code to get all doc ids in the solr server.