Example usage for org.apache.solr.common SolrInputDocument clear

List of usage examples for org.apache.solr.common SolrInputDocument clear

Introduction

In this page you can find the example usage for org.apache.solr.common SolrInputDocument clear.

Prototype

@Override
public void clear() 

Source Link

Document

Remove all fields from the document

Usage

From source file:com.datastax.dse.demos.solr.Wikipedia.java

License:Open Source License

public static boolean addDoc(SolrInputDocument doc, DocData d) {

    if (d.getTitle().indexOf(":") > 0)
        return false;

    doc.clear();
    doc.addField("id", d.getName());
    doc.addField("title", d.getTitle());
    doc.addField("body", d.getBody());
    doc.addField("date", d.getDate());

    return true;/*from   w  w w. j  a  va  2  s  .c  o  m*/
}

From source file:org.openmrs.module.chartsearch.api.db.hibernate.HibernateChartSearchDAO.java

License:Mozilla Public License

/**
 * SQL processing to get patient data to be indexed
 *//*from   ww w .  ja  v  a  2s.c  o  m*/
@SuppressWarnings({ "deprecation", "unchecked" })
@Override
public void indexAllPatientData(Integer numberOfResults, SolrServer solrServer, Class showProgressToClass) {
    PreparedStatement preparedStatement = null;
    SolrInputDocument doc = new SolrInputDocument();
    String sql = " SELECT  o.uuid as id,  obs_id,    person_id,  obs_datetime, obs_group_id, cn1.name as concept_name, cn2.name as coded,  value_datetime, value_numeric, value_text, cc.concept_class_name FROM openmrs.obs o "
            + "inner join (SELECT * FROM openmrs.concept_name c WHERE c.locale = 'en' AND concept_name_type = 'FULLY_SPECIFIED') as cn1 on cn1.concept_id = o.concept_id "
            + "LEFT join (SELECT * FROM openmrs.concept_name c WHERE c.locale = 'en' AND concept_name_type = 'FULLY_SPECIFIED') as cn2 on cn2.concept_id = o.value_coded  "
            + "LEFT join (SELECT DISTINCT o.concept_id, class.name AS concept_class_name FROM concept_class class JOIN concept c ON c.class_id = class.concept_class_id JOIN obs o ON o.concept_id = c.concept_id) AS cc ON cc.concept_id = o.concept_id "
            + "WHERE o.voided=0 AND cn1.voided=0 LIMIT " + numberOfResults;

    try {
        String info = (String) showProgressToClass.getMethod("getIndexingProgressInfo")
                .invoke(showProgressToClass.newInstance());

        info = Context.getMessageSourceService().getMessage("chartsearch.indexing.patientData.fetchingData");
        setIndexingProgressInfo(showProgressToClass, info);

        log.info("SQL Query for indexing all data is: " + sql);

        preparedStatement = getConnection().prepareStatement(sql);
        ResultSet rs = preparedStatement.executeQuery();
        info = Context.getMessageSourceService()
                .getMessage("chartsearch.indexing.patientData.finishedFetchingData");
        setIndexingProgressInfo(showProgressToClass, info);

        while (rs.next()) {
            setResultsFieldValues(rs);
            addResultsFieldValuesToADocument(doc);
            setIndexingProgressInfo(showProgressToClass, info);

            UpdateResponse resp = solrServer.add(doc);

            resp = solrServer.commit(true, true);
            resp = solrServer.optimize(true, true);

            setIndexingProgressInfo(showProgressToClass, info);
            doc.clear();
        }
        info = Context.getMessageSourceService()
                .getMessage("chartsearch.indexing.patientData.finishedIndexingData");
    } catch (Exception e) {
        System.out.println("Error getting mrn log" + e);
    } finally {
        if (preparedStatement != null) {
            try {
                preparedStatement.close();
            } catch (SQLException e) {
                log.error("Error generated while closing statement", e);
            }
        }
    }
}

From source file:org.phenotips.variantstore.db.solr.SolrVariantUtils.java

License:Open Source License

/**
 * Add a document to a SolrClient.//from  w  w  w. jav a 2  s  .c o m
 *
 * @param doc    the SolrDocument do be added
 * @param server the solr server to assist communication with a Solr server
 * @throws DatabaseException DatabaseException
 */
public static void addDoc(SolrInputDocument doc, SolrClient server) throws DatabaseException {
    try {
        server.add(doc);
        doc.clear();
    } catch (SolrServerException | IOException e) {
        throw new DatabaseException("Error adding variants to Solr", e);
    }
}

From source file:org.phenotips.vocabulary.internal.solr.AbstractOWLSolrVocabulary.java

License:Open Source License

/**
 * Create a document for the ontology class, and add it to the index.
 *
 * @param doc the reusable Solr input document
 * @param ontClass the ontology class that should be parsed
 * @param root the top root category for ontClass
 * @param termBatch the batch of newly-processed documents to commit later
 *///  w  ww  .  j av  a  2s  . com
private void addDoc(@Nonnull final SolrInputDocument doc, @Nonnull final OntClass ontClass,
        @Nonnull final OntClass root, Collection<SolrInputDocument> termBatch) {
    parseSolrDocumentFromOntClass(doc, ontClass, root);
    parseSolrDocumentFromOntParentClasses(doc, ontClass);
    extendTerm(new SolrVocabularyInputTerm(doc, this));
    termBatch.add(new SolrInputDocument(doc));
    doc.clear();
}

From source file:org.phenotips.vocabulary.internal.solr.AbstractOWLSolrVocabulary.java

License:Open Source License

/**
 * Sets the ontology version data./* www. j  a va  2s.c om*/
 *
 * @param doc the Solr input document
 * @param ontModel the ontology model
 * @throws IOException if failed to communicate with Solr server while indexing ontology
 * @throws SolrServerException if failed to index ontology
 */
private void setVersion(@Nonnull final SolrInputDocument doc, @Nonnull final OntModel ontModel)
        throws IOException, SolrServerException {
    final String version = ontModel.getOntology(getBaseOntologyUri()).getVersionInfo();
    if (StringUtils.isNotBlank(version)) {
        doc.addField(ID_FIELD_NAME, HEADER_INFO_LABEL);
        doc.addField(VERSION_FIELD_NAME, version);
        this.externalServicesAccess.getSolrConnection(getCoreName()).add(doc);
        doc.clear();
    }
}