Changeset 6319


Ignore:
Timestamp:
06/23/15 11:03:35 (9 years ago)
Author:
teckart@informatik.uni-leipzig.de
Message:

Revised hierarchy update mechanism to get rid of update log in Solr (needed for atomic updates). Instead files are first send to Solr and overwritten with their hierarchy information later. Needs commits after every import for a centre input directory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vlo/trunk/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/MetadataImporter.java

    r6312 r6319  
    1414import java.text.SimpleDateFormat;
    1515import java.util.ArrayList;
    16 import java.util.Arrays;
    1716import java.util.Date;
    1817import java.util.HashMap;
     
    2827import org.apache.commons.cli.PosixParser;
    2928import org.apache.commons.io.FileUtils;
     29import org.apache.solr.client.solrj.SolrQuery;
    3030import org.apache.solr.client.solrj.SolrServerException;
    3131import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrServer;
    3232import org.apache.solr.client.solrj.util.ClientUtils;
     33import org.apache.solr.common.SolrDocumentList;
    3334import org.apache.solr.common.SolrInputDocument;
    3435import org.apache.solr.common.params.MapSolrParams;
     
    155156                        sendDocs();
    156157                    }
     158                    solrServer.commit();
    157159                    updateDocumentHierarchy();
    158160                }
     
    461463    private void updateDocumentHierarchy() throws SolrServerException, MalformedURLException, IOException {
    462464        LOG.info(ResourceStructureGraph.printStatistics(0));
     465        Boolean updatedDocs = false;
    463466        List<SolrInputDocument> updateDocs = new ArrayList<SolrInputDocument>();
    464467        Iterator<CmdiVertex> vertexIter = ResourceStructureGraph.getFoundVertices().iterator();
     
    468471            List<String> outgoingVertexNames = ResourceStructureGraph.getOutgoingVertexNames(vertex);
    469472           
     473            SolrQuery query;
    470474            // update vertex if changes are necessary (necessary if non-default weight or edges to other resources)
    471475            if(vertex.getHierarchyWeight() != 0 || !incomingVertexNames.isEmpty() || !outgoingVertexNames.isEmpty()) {
    472                 SolrInputDocument doc = new SolrInputDocument();
    473                 doc.setField(FacetConstants.FIELD_ID, Arrays.asList(vertex.getId()));
     476                updatedDocs = true;
     477               
     478                // get document
     479                query = new SolrQuery();
     480                query.set("q", FacetConstants.FIELD_ID+":"+vertex.getId());
     481                SolrDocumentList response = solrServer.query(query).getResults();
     482               
     483                // empty result set? may be the case if CMDI file was rejected due to missing ResourceProxys in {@link #processCmdi(File, DataRoot, CMDIDataProcessor) processCmdi}
     484                if(response.size() == 0) {
     485                    LOG.debug("Doc "+vertex.getId()+" not found while updating document hierarchy information");
     486                    continue;
     487                }
     488                SolrInputDocument doc = ClientUtils.toSolrInputDocument(response.get(0));
    474489               
    475490                if(vertex.getHierarchyWeight() != 0) {
    476                     Map<String, Integer> partialUpdate = new HashMap<String, Integer>();
    477                     partialUpdate.put("set", Math.abs(vertex.getHierarchyWeight()));
    478                     doc.addField(FacetConstants.FIELD_HIERARCHY_WEIGHT, partialUpdate);
     491                    doc.setField(FacetConstants.FIELD_HIERARCHY_WEIGHT, Math.abs(vertex.getHierarchyWeight()));
    479492                }
    480493               
    481494                if(!incomingVertexNames.isEmpty()) {
    482                     Map<String, List<String>> partialUpdate = new HashMap<String, List<String>>();
    483                     partialUpdate.put("set", incomingVertexNames);
    484                     doc.setField(FacetConstants.FIELD_HAS_PART, partialUpdate);
     495                    doc.setField(FacetConstants.FIELD_HAS_PART, incomingVertexNames);
    485496                    doc.setField(FacetConstants.FIELD_HAS_PART_COUNT, incomingVertexNames.size());
    486497                }
    487498               
    488499                if(!outgoingVertexNames.isEmpty()) {
    489                     Map<String, List<String>> partialUpdate = new HashMap<String, List<String>>();
    490                     partialUpdate.put("set", outgoingVertexNames);
    491                     doc.setField(FacetConstants.FIELD_IS_PART_OF, partialUpdate);
     500                    doc.setField(FacetConstants.FIELD_IS_PART_OF, outgoingVertexNames);
    492501                }
    493502                updateDocs.add(doc);
     
    508517            }
    509518        }
    510         solrServer.commit();
     519       
     520        if(updatedDocs) {
     521            solrServer.commit();
     522        }
    511523
    512524        ResourceStructureGraph.clearResourceGraph();
Note: See TracChangeset for help on using the changeset viewer.