Example usage for org.apache.solr.common SolrDocument remove

List of usage examples for org.apache.solr.common SolrDocument remove

Introduction

In this page you can find the example usage for org.apache.solr.common SolrDocument remove.

Prototype

@Override
    public Object remove(Object key) 

Source Link

Usage

From source file:geocluster.GeoclusterComponent.java

License:Apache License

private void finishCluster(SolrDocument cluster, String geohashPrefix) {
    // Replace center with latlng string.
    LatLng center = (LatLng) cluster.get(GEOCLUSTER_CENTER);
    cluster.setField(GEOCLUSTER_CENTER, center.getLat() + "," + center.getLng());
    // Replace docs with ids only.
    HashMap<Integer, SolrDocument> docs = (HashMap<Integer, SolrDocument>) cluster
            .getFieldValue(GEOCLUSTER_DOCS);
    cluster.remove(GEOCLUSTER_DOCS);
    cluster.setField(GEOCLUSTER_DOC_IDS, docs.keySet());
    cluster.addField(GEOCLUSTER_COUNT, docs.size());
    cluster.addField("ss_id", geohashPrefix);
}

From source file:org.phenotips.variantstore.db.solr.tasks.AddIndividualTask.java

License:Open Source License

@Override
public Object call() throws Exception {
    GAVariant variant;//w  w  w.j av  a  2 s . co m
    SolrDocument resp;
    SolrDocument doc;

    int hashCollisions = 0;

    String individualId = iterator.getHeader().getIndividualId();

    while (iterator.hasNext()) {
        variant = iterator.next();

        // skip filter!= PASS
        if (!"PASS".equals(VariantUtils.getInfo(variant.getCalls().get(0), GACallInfoFields.FILTER))) {
            continue;
        }

        /**
         * Query Solr for existing variant
         */
        String hash = SolrVariantUtils.getHash(variant);

        resp = null;
        try {
            resp = server.getById(hash);
        } catch (SolrServerException | IOException e) {
            logger.error("Failed to check for an existing variant", e);
            continue;
        }

        if (resp != null) {
            // found a doc, use it.
            doc = resp;
            doc.remove("_version_");
            server.deleteById(hash);
            hashCollisions++;
        } else {
            // our variant is totally new. create a new doc
            doc = SolrVariantUtils.variantToDoc(variant);
        }

        // Either way, add individual-specific fields
        SolrVariantUtils.addVariantToDoc(doc, variant, individualId, iterator.getHeader().isPublic());

        SolrVariantUtils.addDoc(ClientUtils.toSolrInputDocument(doc), server);
    }
    logger.debug("csv: Hash Collisions: " + hashCollisions);

    // updating the metadata document with individual id
    SolrDocument metaDoc = SolrVariantUtils.getMetaDocument(server);
    SolrVariantUtils.addMultiFieldValue(metaDoc, VariantsSchema.CALLSET_IDS, individualId);
    SolrVariantUtils.addDoc(ClientUtils.toSolrInputDocument(metaDoc), server);

    // Solr should commit the fields at it's own optimal pace.
    // We want to commit once at the end to make sure any leftovers in solr buffers are available for querying.
    server.commit(true, true);
    return null;
}

From source file:org.phenotips.variantstore.db.solr.tasks.RemoveIndividualTask.java

License:Open Source License

@Override
public Object call() throws Exception {
    GAVariant variant;// w w  w  .ja  v a  2s . c o m
    SolrDocument resp;
    SolrDocument doc;

    int hashCollisions = 0;
    int hashMisses = 0;

    String individualId = iterator.getHeader().getIndividualId();

    while (iterator.hasNext()) {
        variant = iterator.next();

        // skip filter!= PASS
        if (!"PASS".equals(VariantUtils.getInfo(variant.getCalls().get(0), GACallInfoFields.FILTER))) {
            continue;
        }

        /**
         * Query Solr for existing variant
         */
        String hash = SolrVariantUtils.getHash(variant);

        resp = null;
        try {
            resp = server.getById(hash);
        } catch (SolrServerException | IOException e) {
            logger.error("Failed to check for an existing variant", e);
            continue;
        }

        if (resp == null) {
            // our variant is totally new. how did this happen?
            logger.debug("variant not found");
            hashMisses += 1;
            continue;
        }

        // found a doc, use it.
        doc = resp;
        doc.remove("_version_");
        server.deleteById(hash);
        hashCollisions++;

        SolrVariantUtils.removeVariantFromDoc(doc, variant, individualId, iterator.getHeader().isPublic());
        SolrVariantUtils.addDoc(ClientUtils.toSolrInputDocument(doc), server);
    }
    logger.debug("csv: Hash Collisions: " + hashCollisions);
    logger.debug("csv: Hash Misses: " + hashMisses);

    // removing individual id from the metadata document
    SolrDocument metaDoc = SolrVariantUtils.getMetaDocument(server);
    SolrVariantUtils.removeMultiFieldValue(metaDoc, VariantsSchema.CALLSET_IDS, individualId);
    SolrVariantUtils.addDoc(ClientUtils.toSolrInputDocument(metaDoc), server);

    // Solr should commit the fields at it's own optimal pace.
    // We want to commit once at the end to make sure any leftovers in solr buffers are available for querying.
    server.commit(true, true);
    return null;
}

From source file:org.zaizi.sensefy.api.service.SolrSmartAutoCompleteService.java

License:Open Source License

/**
 * this method prevent the document suggestion field to return more than one
 * value. In this way we would have only one suggestion, and containing the
 * value can be improved using highlight
 *
 * @param titleSuggestions/*  w w w .jav a 2 s .  c  o m*/
 */
private void filterDocumentSuggestions(List<SolrDocument> titleSuggestions,
        Map<String, Map<String, List<String>>> highlightingSnippets) {
    for (SolrDocument doc : titleSuggestions) {
        String docId = (String) doc.get(ID_FIELD);
        doc.remove(DOCUMENT_SUGGESTION);
        if (highlightingSnippets != null) {
            Map<String, List<String>> field2snippet = highlightingSnippets.get(docId);
            if (field2snippet != null) {
                List<String> snippets = field2snippet.get(DOCUMENT_SUGGESTION);
                if (snippets.size() > 0)
                    doc.put(DOCUMENT_SUGGESTION, snippets.get(0));
            }
        }

    }
}