1
|
package edu.ucsb.nceas.metacat.index;
|
2
|
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
3
|
|
4
|
import org.apache.http.impl.client.DefaultHttpClient;
|
5
|
import org.dataone.cn.indexer.solrhttp.HTTPService;
|
6
|
import org.dataone.cn.indexer.solrhttp.SolrDoc;
|
7
|
import org.dataone.cn.indexer.solrhttp.SolrElementAdd;
|
8
|
import org.dataone.cn.indexer.solrhttp.SolrElementField;
|
9
|
|
10
|
import java.io.IOException;
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
import java.util.Map;
|
14
|
|
15
|
public class D1Index implements GenericIndex {
|
16
|
protected final DefaultHttpClient client = new DefaultHttpClient();
|
17
|
protected final HTTPService solrSvc =
|
18
|
new HTTPService(new HttpComponentsClientHttpRequestFactory(this.client));
|
19
|
protected String uri = "";
|
20
|
|
21
|
D1Index(String uri) {
|
22
|
this.uri = uri;
|
23
|
}
|
24
|
|
25
|
public void insert(String docID, Map<String, String[]> fields) throws IOException {
|
26
|
this.update(docID, fields);
|
27
|
}
|
28
|
|
29
|
public void update(String docID, Map<String, String[]> fields) throws IOException {
|
30
|
SolrDoc doc = new SolrDoc();
|
31
|
// this works for our purposes, but violates DataONE expectations
|
32
|
doc.addField(new SolrElementField(SolrElementField.FIELD_ID, docID));
|
33
|
for (String k : fields.keySet()) {
|
34
|
for (String v : fields.get(k)) {
|
35
|
doc.addField(new SolrElementField(k, v));
|
36
|
}
|
37
|
}
|
38
|
List<SolrDoc> docList = new ArrayList<SolrDoc>(1);
|
39
|
docList.add(doc);
|
40
|
solrSvc.sendUpdate(this.uri, new SolrElementAdd(docList));
|
41
|
}
|
42
|
|
43
|
public void remove(String docID) {
|
44
|
solrSvc.sendSolrDelete(docID);
|
45
|
}
|
46
|
|
47
|
public String[] query(String q) throws IndexOutOfBoundsException {
|
48
|
// the indexer's HttpService class doesn't provide general querying -- it's
|
49
|
// an indexer only. Query handling is done by separate code in a different
|
50
|
// part of the D1 architecture. That code is rather tightly bound to other
|
51
|
// D1 elements and consequently challenging to integrate with Metacat.
|
52
|
// For this and other reasons I feel that the other index interfaces are
|
53
|
// a better choice for Metacat, so as yet this remains incomplete. It is
|
54
|
// however possible to continue down this path.
|
55
|
return new String[0];
|
56
|
}
|
57
|
}
|