Revision 7711
Added by Jing Tao over 11 years ago
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/resourcemap/ResourceMapSubprocessor.java | ||
---|---|---|
140 | 140 |
/* |
141 | 141 |
* Get the SolrDoc list for the list of the ids. |
142 | 142 |
*/ |
143 |
private List<SolrDoc> getSolrDocs(List<String> ids) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException {
|
|
143 |
public static List<SolrDoc> getSolrDocs(List<String> ids) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException {
|
|
144 | 144 |
List<SolrDoc> list = new ArrayList<SolrDoc>(); |
145 | 145 |
if(ids != null) { |
146 | 146 |
for(String id : ids) { |
... | ... | |
156 | 156 |
/* |
157 | 157 |
* Get the SolrDoc for the specified id |
158 | 158 |
*/ |
159 |
private SolrDoc getSolrDoc(String id) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException { |
|
159 |
private static SolrDoc getSolrDoc(String id) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException {
|
|
160 | 160 |
SolrDoc solrDoc = null; |
161 | 161 |
if(solrServer != null) { |
162 | 162 |
String query = QUERY+"\""+id+"\""; |
... | ... | |
183 | 183 |
* @param reponse |
184 | 184 |
* @return |
185 | 185 |
*/ |
186 |
private SolrDoc transformQueryResponseToSolrDoc(SolrParams solrParams, QueryResponse response) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException { |
|
186 |
private static SolrDoc transformQueryResponseToSolrDoc(SolrParams solrParams, QueryResponse response) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException {
|
|
187 | 187 |
SolrDoc solrDoc = null; |
188 | 188 |
if(response != null) { |
189 | 189 |
SolrQueryResponseTransformer transformer = new SolrQueryResponseTransformer(solrCore); |
... | ... | |
201 | 201 |
/* |
202 | 202 |
* Parse the query result document. This method only choose the first one from a list. |
203 | 203 |
*/ |
204 |
private SolrDoc parseResults(Document document) throws XPathExpressionException { |
|
204 |
private static SolrDoc parseResults(Document document) throws XPathExpressionException {
|
|
205 | 205 |
SolrDoc solrDoc = null; |
206 | 206 |
NodeList nodeList = (NodeList) XPathFactory.newInstance().newXPath() |
207 | 207 |
.evaluate("/response/result/doc", document, XPathConstants.NODESET); |
... | ... | |
216 | 216 |
/* |
217 | 217 |
* Parse an element |
218 | 218 |
*/ |
219 |
private SolrDoc parseDoc(Element docElement) { |
|
219 |
private static SolrDoc parseDoc(Element docElement) {
|
|
220 | 220 |
List<String> validSolrFieldNames = getValidSchemaField(); |
221 | 221 |
SolrDoc doc = new SolrDoc(); |
222 | 222 |
doc.LoadFromElement(docElement, validSolrFieldNames); |
... | ... | |
228 | 228 |
* Get the valid schema fields from the solr server. |
229 | 229 |
* @return |
230 | 230 |
*/ |
231 |
private List<String> getValidSchemaField() { |
|
231 |
private static List<String> getValidSchemaField() {
|
|
232 | 232 |
List<String> validSolrFieldNames = new ArrayList<String>(); |
233 | 233 |
IndexSchema schema = solrCore.getSchema(); |
234 | 234 |
Map<String, SchemaField> fieldMap = schema.getFields(); |
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/SolrIndex.java | ||
---|---|---|
69 | 69 |
import org.w3c.dom.NameList; |
70 | 70 |
import org.xml.sax.SAXException; |
71 | 71 |
|
72 |
import edu.ucsb.nceas.metacat.index.resourcemap.ResourceMapSubprocessor; |
|
73 |
|
|
72 | 74 |
/** |
73 | 75 |
* A class does insert, update and remove indexes to a SOLR server |
74 | 76 |
* @author tao |
... | ... | |
157 | 159 |
* @throws ParserConfigurationException |
158 | 160 |
* @throws XPathExpressionException |
159 | 161 |
* @throws JiBXException |
162 |
* @throws SolrServerException |
|
160 | 163 |
* @throws EncoderException |
161 | 164 |
*/ |
162 | 165 |
private Map<String, SolrDoc> process(String id, SystemMetadata systemMetadata, InputStream dataStream) |
163 | 166 |
throws IOException, SAXException, ParserConfigurationException, |
164 |
XPathExpressionException, JiBXException{ |
|
167 |
XPathExpressionException, JiBXException, EncoderException, SolrServerException{
|
|
165 | 168 |
|
166 | 169 |
// Load the System Metadata document |
167 | 170 |
ByteArrayOutputStream systemMetadataOutputStream = new ByteArrayOutputStream(); |
... | ... | |
209 | 212 |
// merge is only for resource map. We need more work here. |
210 | 213 |
for (SolrDoc mergeDoc : docs.values()) { |
211 | 214 |
if (!mergeDoc.isMerged()) { |
212 |
//mergeWithIndexedDocument(mergeDoc);
|
|
215 |
mergeWithIndexedDocument(mergeDoc); |
|
213 | 216 |
} |
214 | 217 |
} |
215 | 218 |
|
... | ... | |
218 | 221 |
return docs; |
219 | 222 |
} |
220 | 223 |
|
224 |
/** |
|
225 |
* Merge updates with existing solr documents |
|
226 |
* |
|
227 |
* This method appears to re-set the data package field data into the |
|
228 |
* document about to be updated in the solr index. Since packaging |
|
229 |
* information is derived from the package document (resource map), this |
|
230 |
* information is not present when processing a document contained in a data |
|
231 |
* package. This method replaces those values from the existing solr index |
|
232 |
* record for the document being processed. -- sroseboo, 1-18-12 |
|
233 |
* |
|
234 |
* @param indexDocument |
|
235 |
* @return |
|
236 |
* @throws IOException |
|
237 |
* @throws EncoderException |
|
238 |
* @throws XPathExpressionException |
|
239 |
* @throws SAXException |
|
240 |
* @throws ParserConfigurationException |
|
241 |
* @throws SolrServerException |
|
242 |
*/ |
|
243 |
// TODO:combine merge function with resourcemap merge function |
|
244 |
|
|
245 |
private SolrDoc mergeWithIndexedDocument(SolrDoc indexDocument) throws IOException, |
|
246 |
EncoderException, XPathExpressionException, SolrServerException, ParserConfigurationException, SAXException { |
|
247 |
List<String> ids = new ArrayList<String>(); |
|
248 |
ids.add(indexDocument.getIdentifier()); |
|
249 |
List<SolrDoc> indexedDocuments = ResourceMapSubprocessor.getSolrDocs(ids); |
|
250 |
SolrDoc indexedDocument = indexedDocuments == null || indexedDocuments.size() <= 0 ? null |
|
251 |
: indexedDocuments.get(0); |
|
252 |
if (indexedDocument == null || indexedDocument.getFieldList().size() <= 0) { |
|
253 |
return indexDocument; |
|
254 |
} else { |
|
255 |
for (SolrElementField field : indexedDocument.getFieldList()) { |
|
256 |
if ((field.getName().equals(SolrElementField.FIELD_ISDOCUMENTEDBY) |
|
257 |
|| field.getName().equals(SolrElementField.FIELD_DOCUMENTS) || field |
|
258 |
.getName().equals(SolrElementField.FIELD_RESOURCEMAP)) |
|
259 |
&& !indexDocument.hasFieldWithValue(field.getName(), field.getValue())) { |
|
260 |
indexDocument.addField(field); |
|
261 |
} |
|
262 |
} |
|
263 |
|
|
264 |
indexDocument.setMerged(true); |
|
265 |
return indexDocument; |
|
266 |
} |
|
267 |
} |
|
268 |
|
|
221 | 269 |
/* |
222 | 270 |
* Generate a Document from the InputStream |
223 | 271 |
*/ |
... | ... | |
281 | 329 |
* @param data the data object itself |
282 | 330 |
* @throws SolrServerException |
283 | 331 |
* @throws JiBXException |
332 |
* @throws EncoderException |
|
284 | 333 |
*/ |
285 | 334 |
private synchronized void insert(String pid, SystemMetadata systemMetadata, InputStream data) |
286 | 335 |
throws IOException, SAXException, ParserConfigurationException, |
287 |
XPathExpressionException, SolrServerException, JiBXException { |
|
336 |
XPathExpressionException, SolrServerException, JiBXException, EncoderException {
|
|
288 | 337 |
checkParams(pid, systemMetadata, data); |
289 | 338 |
Map<String, SolrDoc> docs = process(pid, systemMetadata, data); |
290 | 339 |
|
... | ... | |
335 | 384 |
* @param data the data object itself |
336 | 385 |
* @throws SolrServerException |
337 | 386 |
* @throws JiBXException |
387 |
* @throws EncoderException |
|
338 | 388 |
*/ |
339 | 389 |
public void update(String pid, List<String> obsoleteIds, SystemMetadata systemMetadata, InputStream data) |
340 | 390 |
throws IOException, SAXException, ParserConfigurationException, |
341 |
XPathExpressionException, SolrServerException, JiBXException { |
|
391 |
XPathExpressionException, SolrServerException, JiBXException, EncoderException {
|
|
342 | 392 |
checkParams(pid, systemMetadata, data); |
343 | 393 |
boolean isArchive = systemMetadata.getArchived(); |
344 | 394 |
if(isArchive) { |
Also available in: Unified diff
Add the code to add a resource map information.