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

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

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:com.doculibre.constellio.servlets.SolrJExampleMain.java

License:Open Source License

/**
 * Print documents and facets/*from ww  w.j a v a 2 s  .  c  om*/
 * 
 * @param response
 */
@SuppressWarnings("unchecked")
public static void print(QueryResponse response) {
    SolrDocumentList docs = response.getResults();
    if (docs != null) {
        System.out.println(docs.getNumFound() + " documents found, " + docs.size() + " returned : ");
        for (int i = 0; i < docs.size(); i++) {
            SolrDocument doc = docs.get(i);
            System.out.println("\t" + doc.toString());
        }
    }

    List<FacetField> fieldFacets = response.getFacetFields();
    if (fieldFacets != null && fieldFacets.isEmpty()) {
        System.out.println("\nField Facets : ");
        for (FacetField fieldFacet : fieldFacets) {
            System.out.print("\t" + fieldFacet.getName() + " :\t");
            if (fieldFacet.getValueCount() > 0) {
                for (Count count : fieldFacet.getValues()) {
                    System.out.print(count.getName() + "[" + count.getCount() + "]\t");
                }
            }
            System.out.println("");
        }
    }

    Map<String, Integer> queryFacets = response.getFacetQuery();
    if (queryFacets != null && !queryFacets.isEmpty()) {
        System.out.println("\nQuery facets : ");
        for (String queryFacet : queryFacets.keySet()) {
            System.out.println("\t" + queryFacet + "\t[" + queryFacets.get(queryFacet) + "]");
        }
        System.out.println("");
    }

    NamedList<NamedList<Object>> spellCheckResponse = (NamedList<NamedList<Object>>) response.getResponse()
            .get("spellcheck");

    if (spellCheckResponse != null) {
        Iterator<Entry<String, NamedList<Object>>> wordsIterator = spellCheckResponse.iterator();

        while (wordsIterator.hasNext()) {
            Entry<String, NamedList<Object>> entry = wordsIterator.next();
            String word = entry.getKey();
            NamedList<Object> spellCheckWordResponse = entry.getValue();
            boolean correct = spellCheckWordResponse.get("frequency").equals(1);
            System.out.println("Word: " + word + ",\tCorrect?: " + correct);
            NamedList<Integer> suggestions = (NamedList<Integer>) spellCheckWordResponse.get("suggestions");
            if (suggestions != null && suggestions.size() > 0) {
                System.out.println("Suggestions : ");
                Iterator<Entry<String, Integer>> suggestionsIterator = suggestions.iterator();
                while (suggestionsIterator.hasNext()) {
                    System.out.println("\t" + suggestionsIterator.next().getKey());
                }

            }
            System.out.println("");
        }

    }

}

From source file:net.peacesoft.nutch.crawl.RaovatPostSignature.java

License:Apache License

public void reduce(Text key, Iterator<RaovatPostSignature.SolrRecord> values,
        OutputCollector<Text, RaovatPostSignature.SolrRecord> output, Reporter reporter) throws IOException {
    while (values.hasNext()) {
        RaovatPostSignature.SolrRecord solrRecord = values.next();

        try {//ww  w .  j a  va  2 s .c  o m
            SolrQuery solrQuery = new SolrQuery("id:" + key);

            QueryResponse response;
            try {
                response = solr.query(solrQuery);
            } catch (final SolrServerException e) {
                throw new IOException(e);
            }

            final SolrDocumentList solrDocs = response.getResults();
            for (SolrDocument solrDocument : solrDocs) {
                LOG.info(solrDocument.toString());
                updateRequest.add(ClientUtils.toSolrInputDocument(solrDocument));
            }
            LOG.info("RaovatPostSignature sign the key to signature field id " + key + " value "
                    + solrDocs.size());
        } catch (Exception ex) {
            LOG.error("RaovatPostSignature reduce error: " + ex.toString(), ex);
        }
        if (numDeletes >= NUM_MAX_DELETE_REQUEST) {
            try {
                LOG.info("RaovatPostSignature: signed " + numDeletes + " key");
                updateRequest.process(solr);
            } catch (SolrServerException e) {
                throw new IOException(e);
            }
            updateRequest = new UpdateRequest();
            numDeletes = 0;
        }
    }
}

From source file:org.apache.ranger.solr.SolrAccessAuditsService.java

License:Apache License

/**
 * @param doc// www .  j a va2s .co  m
 * @return
 */
private VXAccessAudit populateViewBean(SolrDocument doc) {
    VXAccessAudit accessAudit = new VXAccessAudit();
    Object value = null;
    if (logger.isDebugEnabled()) {
        logger.debug("doc=" + doc.toString());
    }

    value = doc.getFieldValue("id");
    if (value != null) {
        // TODO: Converting ID to hashcode for now
        accessAudit.setId((long) value.hashCode());
    }

    value = doc.getFieldValue("access");
    if (value != null) {
        accessAudit.setAccessType(value.toString());
    }

    value = doc.getFieldValue("enforcer");
    if (value != null) {
        accessAudit.setAclEnforcer(value.toString());
    }
    value = doc.getFieldValue("agent");
    if (value != null) {
        accessAudit.setAgentId(value.toString());
    }
    value = doc.getFieldValue("repo");
    if (value != null) {
        accessAudit.setRepoName(value.toString());
    }
    value = doc.getFieldValue("sess");
    if (value != null) {
        accessAudit.setSessionId(value.toString());
    }
    value = doc.getFieldValue("reqUser");
    if (value != null) {
        accessAudit.setRequestUser(value.toString());
    }
    value = doc.getFieldValue("reqData");
    if (value != null) {
        accessAudit.setRequestData(value.toString());
    }
    value = doc.getFieldValue("resource");
    if (value != null) {
        accessAudit.setResourcePath(value.toString());
    }
    value = doc.getFieldValue("cliIP");
    if (value != null) {
        accessAudit.setClientIP(value.toString());
    }
    value = doc.getFieldValue("logType");
    if (value != null) {
        // TODO: Need to see what logType maps to in UI
        //         accessAudit.setAuditType(solrUtil.toInt(value));
    }
    value = doc.getFieldValue("result");
    if (value != null) {
        accessAudit.setAccessResult(solrUtil.toInt(value));
    }
    value = doc.getFieldValue("policy");
    if (value != null) {
        accessAudit.setPolicyId(solrUtil.toLong(value));
    }
    value = doc.getFieldValue("repoType");
    if (value != null) {
        accessAudit.setRepoType(solrUtil.toInt(value));
        XXServiceDef xServiceDef = daoManager.getXXServiceDef().getById((long) accessAudit.getRepoType());
        if (xServiceDef != null) {
            accessAudit.setServiceType(xServiceDef.getName());
        }
    }
    value = doc.getFieldValue("resType");
    if (value != null) {
        accessAudit.setResourceType(value.toString());
    }
    value = doc.getFieldValue("reason");
    if (value != null) {
        accessAudit.setResultReason(value.toString());
    }
    value = doc.getFieldValue("action");
    if (value != null) {
        accessAudit.setAction(value.toString());
    }
    value = doc.getFieldValue("evtTime");
    if (value != null) {
        accessAudit.setEventTime(solrUtil.toDate(value));
    }
    value = doc.getFieldValue("seq_num");
    if (value != null) {
        accessAudit.setSequenceNumber(solrUtil.toLong(value));
    }
    value = doc.getFieldValue("event_count");
    if (value != null) {
        accessAudit.setEventCount(solrUtil.toLong(value));
    }
    value = doc.getFieldValue("event_dur_ms");
    if (value != null) {
        accessAudit.setEventDuration(solrUtil.toLong(value));
    }
    value = doc.getFieldValue("tags");
    if (value != null) {
        accessAudit.setTags(value.toString());
    }
    return accessAudit;
}

From source file:org.dspace.app.xmlui.aspect.discovery.AbstractFiltersTransformer.java

License:Open Source License

/**
 * Generate the cache validity object.// w ww  .ja v a 2 s. c  om
 * <p/>
 * The validity object will include the collection being viewed and
 * all recently submitted items. This does not include the community / collection
 * hierarch, when this changes they will not be reflected in the cache.
 */
public SourceValidity getValidity() {
    if (this.validity == null) {

        try {
            DSpaceObject dso = HandleUtil.obtainHandle(objectModel);

            DSpaceValidity val = new DSpaceValidity();

            // add reciently submitted items, serialize solr query contents.
            performSearch(dso);

            // Add the actual collection;
            if (dso != null)
                val.add(dso);

            val.add("numFound:" + queryResults.getResults().getNumFound());

            for (SolrDocument doc : queryResults.getResults()) {
                val.add(doc.toString());
            }

            //                for (SolrDocument doc : queryResults.getResults()) {
            //                    val.add(doc.toString());
            //                }

            for (FacetField field : queryResults.getFacetFields()) {
                val.add(field.getName());

                for (FacetField.Count count : field.getValues()) {
                    val.add(count.getName() + count.getCount());
                }
            }

            this.validity = val.complete();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        //TODO: dependent on tags as well :)
    }
    return this.validity;
}

From source file:org.dspace.app.xmlui.aspect.discovery.AbstractSearch.java

License:Open Source License

/**
 * Generate the cache validity object./*from   w w  w.  j a v a 2s.  co  m*/
 * <p/>
 * This validity object should never "over cache" because it will
 * perform the search, and serialize the results using the
 * DSpaceValidity object.
 */
public SourceValidity getValidity() {
    if (this.validity == null) {
        try {
            DSpaceValidity validity = new DSpaceValidity();

            DSpaceObject scope = getScope();
            validity.add(scope);

            performSearch(scope);

            SolrDocumentList results = this.queryResults.getResults();

            if (results != null) {
                validity.add("size:" + results.size());

                for (SolrDocument result : results) {
                    validity.add(result.toString());
                }
            }

            this.validity = validity.complete();
        } catch (Exception e) {
            // Just ignore all errors and return an invalid cache.
        }

        // add log message that we are viewing the item
        // done here, as the serialization may not occur if the cache is valid
        logSearch();
    }
    return this.validity;
}

From source file:org.dspace.app.xmlui.aspect.discovery.BrowseFacet.java

License:Open Source License

/**
 * Generate the cache validity object.//from  w  ww .  j  ava  2  s .  c om
 * <p/>
 * The validity object will include the collection being viewed and
 * all recently submitted items. This does not include the community / collection
 * hierarch, when this changes they will not be reflected in the cache.
 */
@Override
public SourceValidity getValidity() {
    if (this.validity == null) {

        try {
            DSpaceValidity validity = new DSpaceValidity();

            DSpaceObject dso = HandleUtil.obtainHandle(objectModel);

            if (dso != null) {
                // Add the actual collection;
                validity.add(dso);
            }

            // add reciently submitted items, serialize solr query contents.
            QueryResponse response = getQueryResponse(dso);

            validity.add("numFound:" + response.getResults().getNumFound());

            //                for (SolrDocument doc : response.getResults()) {
            //                    validity.add(doc.toString());
            //                }

            for (SolrDocument doc : response.getResults()) {
                validity.add(doc.toString());
            }

            for (FacetField field : response.getFacetFields()) {
                validity.add(field.getName());

                for (FacetField.Count count : field.getValues()) {
                    validity.add(count.getName() + "#" + count.getCount());
                }
            }

            this.validity = validity.complete();
        } catch (Exception e) {
            // Just ignore all errors and return an invalid cache.
        }

        //TODO: dependent on tags as well :)
    }
    return this.validity;
}

From source file:org.dspace.app.xmlui.aspect.discovery.SearchFacetFilter.java

License:BSD License

/**
 * Generate the cache validity object./*  w w w .  jav a 2 s . com*/
 * <p/>
 * The validity object will include the collection being viewed and
 * all recently submitted items. This does not include the community / collection
 * hierarch, when this changes they will not be reflected in the cache.
 */
public SourceValidity getValidity() {
    if (this.validity == null) {

        try {
            DSpaceValidity validity = new DSpaceValidity();

            DSpaceObject dso = HandleUtil.obtainHandle(objectModel);

            if (dso != null) {
                // Add the actual collection;
                validity.add(dso);
            }

            // add reciently submitted items, serialize solr query contents.
            QueryResponse response = getQueryResponse(dso);

            validity.add("numFound:" + response.getResults().getNumFound());

            for (SolrDocument doc : response.getResults()) {
                validity.add(doc.toString());
            }

            for (SolrDocument doc : response.getResults()) {
                validity.add(doc.toString());
            }

            for (FacetField field : response.getFacetFields()) {
                validity.add(field.getName());

                for (FacetField.Count count : field.getValues()) {
                    validity.add(count.getName() + count.getCount());
                }
            }

            this.validity = validity.complete();
        } catch (Exception e) {
            // Just ignore all errors and return an invalid cache.
        }

        //TODO: dependent on tags as well :)
    }
    return this.validity;
}

From source file:org.openmrs.module.chartsearch.solr.ChartSearchSearcher.java

License:Mozilla Public License

public void searchAppointmentsAndGenerateSolrDoc(Integer patientId, String searchText, SolrServer solrServer,
        List<ChartListItem> list) throws SolrServerException {
    SolrQuery query5 = new SolrQuery(String.format("appointment_text:(%s)", searchText));

    query5.addFilterQuery(String.format("patient_id:%d", patientId));
    QueryResponse response5 = solrServer.query(query5);
    Iterator<SolrDocument> iter5 = response5.getResults().iterator();

    while (iter5.hasNext()) {
        SolrDocument doc = iter5.next();
        AppointmentItem item = new AppointmentItem();
        item.setUuid((String) doc.get("id"));
        item.setAppointmentId((Integer) doc.get("appointment_id"));
        item.setProvider((String) doc.get("appointment_provider"));
        item.setStatus((String) doc.get("appointment_status"));
        item.setReason((String) doc.get("appointment_reason"));
        item.setType((String) doc.get("appointment_type"));
        item.setStart((Date) doc.get("appointment_start"));
        item.setEnd((Date) doc.get("appointment_end"));
        item.setTypeDesc((String) doc.get("appointment_typeDesc"));
        item.setCancelReason((String) doc.get("appointment_cancelReason"));
        item.setLocation((String) doc.get("appointment_location"));

        list.add(item);// w  w  w  .j a va  2 s  .c o  m

        System.out.println("FOUND APPOINTMENT: " + doc.toString());
    }
}

From source file:org.openmrs.module.chartsearch.solr.ChartSearchSearcher.java

License:Mozilla Public License

public void searchAllergiesAndGenerateSolrDoc(Integer patientId, String searchText, SolrServer solrServer,
        List<ChartListItem> list) throws SolrServerException {
    SolrQuery query4 = new SolrQuery(String.format("allergy_text:(%s)", searchText));

    query4.addFilterQuery(String.format("patient_id:%d", patientId));
    QueryResponse response4 = solrServer.query(query4);
    Iterator<SolrDocument> iter4 = response4.getResults().iterator();

    while (iter4.hasNext()) {
        SolrDocument document = iter4.next();
        AllergyItem item = new AllergyItem();
        item.setUuid((String) document.get("id"));
        item.setAllergyId((Integer) document.get("allergy_id"));
        item.setAllergenCodedName((String) document.get("allergy_coded_name"));
        item.setAllergenNonCodedName((String) document.get("allergy_non_coded_name"));
        item.setAllergenSeverity((String) document.get("allergy_severity"));
        item.setAllergenType((String) document.get("allergy_type"));
        item.setAllergenCodedReaction((String) document.get("allergy_coded_reaction"));
        item.setAllergenNonCodedReaction((String) document.get("allergy_non_coded_reaction"));
        item.setAllergenComment((String) document.get("allergy_comment"));
        item.setAllergenDate((Date) document.get("allergy_date"));

        list.add(item);/*from ww w.  j a  v  a2 s  .co  m*/

        System.out.println("FOUND ALLERGY: " + document.toString());
    }
}