Skip to content

Add go indexer #1312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: stage
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.alliancegenome.indexer.indexers.ModelIndexer;
import org.alliancegenome.indexer.indexers.curation.DiseaseAnnotationCurationIndexer;
import org.alliancegenome.indexer.indexers.curation.DiseaseSummaryCurationIndexer;
import org.alliancegenome.indexer.indexers.curation.GOSearchResultCurationIndexer;
import org.alliancegenome.indexer.indexers.curation.GeneGeneticInteractionCurationIndexer;
import org.alliancegenome.indexer.indexers.curation.GeneMolecularInteractionCurationIndexer;
import org.alliancegenome.indexer.indexers.curation.GeneToGeneOrthologyIndexer;
Expand All @@ -34,6 +35,7 @@ public enum IndexerConfig {
ReleaseInfoIndexer("release", ReleaseInfoIndexer.class, 1, 1, 1, 1, 1),
DiseaseSummaryIndexer("diseaseSummary", DiseaseSummaryCurationIndexer.class, 4, 1500, 1500, 4, 1),
GeneToGeneOrthologyIndexer("geneToGeneOrthology", GeneToGeneOrthologyIndexer.class, 4, 1500, 1500, 8, 1),
GOSearchResultCurationIndexer("goCuration", GOSearchResultCurationIndexer.class, 4, 1500, 1500, 8, 1),
//GeneExpressionAnnotationIndexer("geneExpressionAnnotation", GeneExpressionAnnotationIndexer.class, 4, 1500, 1500, 2, 1),
//GeneSearchResultCurationIndexer("geneSearchResult", GeneSearchResultCurationIndexer.class, 4, 250, 1000, 4, 1),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.alliancegenome.indexer.indexers.curation;

import java.util.HashMap;
import java.util.concurrent.LinkedBlockingDeque;

import com.fasterxml.jackson.databind.ObjectMapper;

import org.alliancegenome.core.config.ConfigHelper;
import org.alliancegenome.curation_api.interfaces.document.GODocumentInterface;
import org.alliancegenome.curation_api.model.document.es.GOSearchResultDocument;
import org.alliancegenome.curation_api.response.SearchResponse;
import org.alliancegenome.indexer.RestConfig;
import org.alliancegenome.indexer.config.IndexerConfig;
import org.alliancegenome.indexer.indexers.Indexer;
import org.apache.commons.collections.CollectionUtils;

import lombok.extern.slf4j.Slf4j;
import si.mazi.rescu.RestProxyFactory;

@Slf4j
public class GOSearchResultCurationIndexer extends Indexer {

private final GODocumentInterface goApi = RestProxyFactory.createProxy(GODocumentInterface.class,
ConfigHelper.getCurationApiUrl(), RestConfig.config);

private HashMap<String, Object> params = new HashMap<String, Object>() {
{
put("internal", false);
put("obsolete", false);
}
};

public GOSearchResultCurationIndexer(IndexerConfig indexerConfig) {
super(indexerConfig);
}

@Override
protected void index() {
try {
SearchResponse<GOSearchResultDocument> response = goApi.findSearchResult(0, 0, params);
int totalPages = (int) (response.getTotalResults() / indexerConfig.getBufferSize());
LinkedBlockingDeque<String> queue = new LinkedBlockingDeque<>();
for (int i = 0; i <= totalPages; i++) {
queue.add(String.valueOf(i));
}
initiateThreading(queue);
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
protected void startSingleThread(LinkedBlockingDeque<String> queue) {
while (true) {
try {
if (queue.isEmpty()) {
return;
}
String page = queue.takeFirst();
SearchResponse<GOSearchResultDocument> response = goApi.findSearchResult(Integer.valueOf(page),
indexerConfig.getBufferSize(), params);
if (response == null || CollectionUtils.isEmpty(response.getResults())) {
return;
}

indexDocuments(response.getResults());
} catch (Exception e) {
log.error("Error while indexing...", e);
System.exit(-1);
return;
}
}
}

@Override
protected ObjectMapper customizeObjectMapper(ObjectMapper objectMapper) {
return RestConfig.config.getJacksonObjectMapperFactory().createObjectMapper();
}
}
Loading