10 |
10 |
|
11 |
11 |
|
12 |
12 |
|
|
13 |
import org.apache.solr.client.solrj.SolrServer;
|
|
14 |
import org.apache.solr.client.solrj.SolrServerException;
|
|
15 |
import org.apache.solr.client.solrj.response.QueryResponse;
|
|
16 |
import org.apache.solr.common.SolrDocument;
|
|
17 |
import org.apache.solr.common.SolrDocumentList;
|
|
18 |
import org.apache.solr.common.params.SolrParams;
|
|
19 |
import org.apache.solr.servlet.SolrRequestParsers;
|
13 |
20 |
import org.dataone.service.types.v1.SystemMetadata;
|
14 |
21 |
import org.dataone.service.util.TypeMarshaller;
|
15 |
22 |
import org.junit.Test;
|
... | ... | |
30 |
37 |
SystemMetadata systemMetadata = TypeMarshaller.unmarshalTypeFromFile(SystemMetadata.class, SYSTEMMETAFILEPATH);
|
31 |
38 |
InputStream emlInputStream = new FileInputStream(new File(EMLFILEPATH));
|
32 |
39 |
solrIndex.insert(id, systemMetadata, emlInputStream);
|
33 |
|
|
|
40 |
doQuery(solrIndex.getSolrServer());
|
34 |
41 |
}
|
35 |
42 |
|
36 |
43 |
/**
|
... | ... | |
50 |
57 |
SolrIndex index = solrIndexesarray[0];
|
51 |
58 |
return index;
|
52 |
59 |
}
|
|
60 |
|
|
61 |
/*
|
|
62 |
* Do query
|
|
63 |
*/
|
|
64 |
private void doQuery(SolrServer server)
|
|
65 |
throws SolrServerException {
|
|
66 |
StringBuffer request = new StringBuffer();
|
|
67 |
request.append("q=" + "*:*");
|
|
68 |
SolrParams solrParams = SolrRequestParsers.parseQueryString(request
|
|
69 |
.toString());
|
|
70 |
QueryResponse reponse = server.query(solrParams);
|
|
71 |
System.out.println(reponse.toString());
|
|
72 |
}
|
|
73 |
|
|
74 |
|
|
75 |
/*
|
|
76 |
* Print out the QueryResponse
|
|
77 |
*/
|
|
78 |
private void print(QueryResponse response) {
|
|
79 |
SolrDocumentList docs = response.getResults();
|
|
80 |
if (docs != null) {
|
|
81 |
System.out.println(docs.getNumFound() + " documents found, "
|
|
82 |
+ docs.size() + " returned : ");
|
|
83 |
for (int i = 0; i < docs.size(); i++) {
|
|
84 |
SolrDocument doc = docs.get(i);
|
|
85 |
System.out.println("\t" + doc.toString());
|
|
86 |
}
|
|
87 |
}
|
|
88 |
}
|
53 |
89 |
}
|
54 |
90 |
|
Add a query method in the test.