Skip to content
Snippets Groups Projects
Commit 262b0718 authored by mbrodhu's avatar mbrodhu
Browse files

better performance in ListIdentifiers

parent 41e3566e
No related branches found
No related tags found
No related merge requests found
...@@ -4,8 +4,14 @@ import java.util.ArrayList; ...@@ -4,8 +4,14 @@ import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import org.classicmayan.tools.Queries; import org.classicmayan.tools.Queries;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.SearchHit;
import info.textgrid.middleware.oaipmh.ListIdentifiersType; import info.textgrid.middleware.oaipmh.ListIdentifiersType;
import info.textgrid.middleware.oaipmh.ResumptionTokenType; import info.textgrid.middleware.oaipmh.ResumptionTokenType;
...@@ -15,7 +21,7 @@ import info.textgrid.middleware.oaipmh.ResumptionTokenType; ...@@ -15,7 +21,7 @@ import info.textgrid.middleware.oaipmh.ResumptionTokenType;
public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstract { public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstract {
static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>();
private boolean foundItems;
/** /**
* @param textgrid * @param textgrid
* @param dariah * @param dariah
...@@ -35,38 +41,85 @@ public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstrac ...@@ -35,38 +41,85 @@ public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstrac
String resTokenValue = resumptionToken; String resTokenValue = resumptionToken;
QueryBuilder recordFilterForClassicMayan;
QueryBuilder rangeQuery;
rangeQuery = QueryBuilders.rangeQuery("lastModified").from(from).to(to);
recordFilterForClassicMayan = QueryBuilders.boolQuery().must(rangeQuery)
.must(QueryBuilders.matchPhraseQuery("project.id", "TGPR-0e926f53-1aba-d415-ecf6-539edcd8a318"))
.must(QueryBuilders.matchPhraseQuery("format", "text/tg.inputform+rdf+xml"))
.must(QueryBuilders.matchPhraseQuery("notes", "ARTEFACT"));
ListIdentifiersType identifierList = new ListIdentifiersType(); ListIdentifiersType identifierList = new ListIdentifiersType();
List<String> artefactURIs = new ArrayList<String>(); //List<String> artefactURIs = new ArrayList<String>();
Queries queries = new Queries(); //Queries queries = new Queries();
SearchResponse scrollResp;
if (resumptionToken == null) { if (resumptionToken == null) {
artefactURIs = queries.getArtefactList(0); //artefactURIs = queries.getArtefactList(0);
scrollResp = OAI_ESClient.getOaiESClient()
.prepareSearch("textgrid-nonpublic")
.setScroll(TimeValue.timeValueHours(24L))
.setTypes(OAI_ESClient.getEsType())
.addFields("lastModified", "textgridUri", "project.id")
.setQuery(recordFilterForClassicMayan)
.setSize(30)
.execute()
.actionGet();
// Create resumption token for every request only (we do need the same token for resuming // Create resumption token for every request only (we do need the same token for resuming
// because we are using a hash map for counting the calls). // because we are using a hash map for counting the calls).
resTokenValue = UUID.randomUUID().toString(); //resTokenValue = UUID.randomUUID().toString();
} else { } else {
// Use given resumption token here. // Use given resumption token here.
artefactURIs = queries.getArtefactList(cursorCollector.get(resumptionToken)); scrollResp = OAI_ESClient.getOaiESClient().prepareSearchScroll(resumptionToken)
.setScroll(TimeValue.timeValueHours(24L)).execute().actionGet();
} }
long listSize = Queries.getAmountOfArtefacts(); String scrollID = scrollResp.getScrollId();
int i = 0;
long completeListSize = scrollResp.getHits().totalHits();
for (String artefactURI : artefactURIs) {
//long listSize = Queries.getAmountOfArtefacts();
if (completeListSize > 0) {
setFoundItems(true);
int i = 0;
for (SearchHit hit : scrollResp.getHits().getHits()) {
String textgridURI = hit.getFields().get("textgridUri").getValue().toString().replace(".0", "");
RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false);
identifierList.getHeader()
.add(idiomRecord.getRecordById(textgridURI).getRecord().getHeader());
}
/* for (String artefactURI : artefactURIs) {
RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false);
identifierList.getHeader() identifierList.getHeader()
.add(idiomRecord.getRecordById(artefactURI).getRecord().getHeader()); .add(idiomRecord.getRecordById(artefactURI).getRecord().getHeader());
i++; i++;
} }*/
// Check the need for a resumption token! // Check the need for a resumption token!
ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken(listSize, ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken(completeListSize,
resumptionToken, cursorCollector, resTokenValue, 30, i); resumptionToken, cursorCollector, scrollID, 30, i);
if (resTokenForResponse != null) { if (resTokenForResponse != null) {
identifierList.setResumptionToken(resTokenForResponse); identifierList.setResumptionToken(resTokenForResponse);
} }
}else {
setFoundItems(false);
}
return identifierList; return identifierList;
} }
public boolean isFoundItems() {
return foundItems;
}
public void setFoundItems(boolean foundItems) {
this.foundItems = foundItems;
}
} }
package info.textgrid.middleware; package info.textgrid.middleware;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.classicmayan.tools.Queries;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
...@@ -70,7 +67,7 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { ...@@ -70,7 +67,7 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract {
QueryBuilder recordFilterForClassicMayan; QueryBuilder recordFilterForClassicMayan;
QueryBuilder rangeQuery; QueryBuilder rangeQuery;
Queries queries = new Queries(); //Queries queries = new Queries();
//List<String> artefactURIs = queries.getArtefactList(); //List<String> artefactURIs = queries.getArtefactList();
rangeQuery = QueryBuilders.rangeQuery("lastModified").from(from).to(to); rangeQuery = QueryBuilders.rangeQuery("lastModified").from(from).to(to);
...@@ -106,14 +103,12 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { ...@@ -106,14 +103,12 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract {
setFoundItems(true); setFoundItems(true);
int i = 0; int i = 0;
//System.out.println("inside "); //System.out.println("inside ");
for (SearchHit hit : scrollResp.getHits().getHits()) { for (SearchHit hit : scrollResp.getHits().getHits()) {
i++; i++;
String textgridURI = hit.getFields().get("textgridUri").getValue().toString().replace(".0", ""); String textgridURI = hit.getFields().get("textgridUri").getValue().toString().replace(".0", "");
System.out.println("Processing: " + textgridURI); System.out.println("Processing: " + textgridURI);
RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false);
recordList.getRecord().add(idiomRecord.getRecordById(textgridURI).getRecord()); recordList.getRecord().add(idiomRecord.getRecordById(textgridURI).getRecord());
} }
// Check the need for a resumption token! // Check the need for a resumption token!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment