Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Commit

Permalink
PT-497: Add the possibility to reindex OMIM from the administration
Browse files Browse the repository at this point in the history
Store the current version
  • Loading branch information
sdumitriu committed Oct 6, 2015
1 parent 88cb93d commit a60856e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@
import javax.inject.Singleton;

import org.apache.commons.lang3.StringUtils;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.util.ClientUtils;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.DisMaxParams;
Expand Down Expand Up @@ -158,6 +162,26 @@ private SolrParams produceDynamicSolrParams(String originalQuery, Integer rows,
return params;
}

@Override
public String getVersion()
{
SolrQuery query = new SolrQuery();
query.setQuery("version:*");
query.set(CommonParams.ROWS, "1");
try {
QueryResponse response = this.externalServicesAccess.getSolrConnection().query(query);
SolrDocumentList termList = response.getResults();
if (!termList.isEmpty()) {
return termList.get(0).getFieldValue("version").toString();
}
} catch (SolrServerException | SolrException ex) {
this.logger.warn("Failed to query vocabulary version: {}", ex.getMessage());
} catch (IOException ex) {
this.logger.error("IOException while getting vocabulary version", ex);
}
return null;
}

@Override
public synchronized int reindex(String sourceURL)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.apache.commons.csv.CSVRecord;
import org.apache.commons.lang3.StringUtils;
import org.apache.solr.common.SolrInputDocument;
import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -123,6 +125,7 @@ public OmimSourceParser(Vocabulary hpo, String sourceURL)
loadSymptoms(true);
loadSymptoms(false);
loadGeneReviews();
loadVersion();
} catch (NullPointerException | CompressorException | IOException ex) {
this.logger.error("Failed to prepare the OMIM index: {}", ex.getMessage(), ex);
}
Expand Down Expand Up @@ -282,4 +285,12 @@ private void loadGeneReviews()
this.logger.error("Failed to load OMIM-GeneReviews links: {}", ex.getMessage(), ex);
}
}

private void loadVersion()
{
SolrInputDocument metaTerm = new SolrInputDocument();
metaTerm.addField(ID_FIELD, "HEADER_INFO");
metaTerm.addField("version", ISODateTimeFormat.dateTime().withZoneUTC().print(new DateTime()));
this.data.put("VERSION", metaTerm);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
</types>

<fields>
<field name="version" type="string" indexed="true" stored="true" omitNorms="true"/>
<field name="id" type="string" indexed="true" stored="true" required="true" />
<field name="name" type="text_general" indexed="true" stored="true"/>
<field name="nameSpell" type="text_spell" indexed="true" stored="false"/>
Expand Down

0 comments on commit a60856e

Please sign in to comment.