Skip to content
Snippets Groups Projects
Commit 250d615d authored by mbrodhu's avatar mbrodhu
Browse files

enable get alluris with elasticsearch instaed of triplestore

parent dea64b6c
No related branches found
No related tags found
No related merge requests found
...@@ -418,9 +418,11 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -418,9 +418,11 @@ public class OAIPMHImpl implements OAIPMHProducer {
&& RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken()); && RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken());
boolean restokIDIOMExisting = RecordListDelivererIDIOM.cursorCollector != null boolean restokIDIOMExisting = RecordListDelivererIDIOM.cursorCollector != null
&& RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken()); && RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken());
System.out.println("OAIIMPL: " + request.getResumptionToken());
if (restokDCExisting) { if (restokDCExisting) {
recListDeliv = this.recordListDC; recListDeliv = this.recordListDC;
} else if (restokIDIOMExisting) { } else if (restokIDIOMExisting) {
System.out.println("DUMDIDUM");
recListDeliv = this.recordListIDIOM; recListDeliv = this.recordListIDIOM;
} }
} }
......
...@@ -6,6 +6,12 @@ import java.util.Map; ...@@ -6,6 +6,12 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
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.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import info.textgrid.middleware.oaipmh.HeaderType; import info.textgrid.middleware.oaipmh.HeaderType;
import info.textgrid.middleware.oaipmh.ListRecordsType; import info.textgrid.middleware.oaipmh.ListRecordsType;
import info.textgrid.middleware.oaipmh.MetadataType; import info.textgrid.middleware.oaipmh.MetadataType;
...@@ -21,12 +27,14 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { ...@@ -21,12 +27,14 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract {
static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>();
private OAI_ESClient oaiEsClient; private OAI_ESClient oaiEsClient;
private boolean foundItems;
/** /**
* @param textgrid * @param textgrid
* @param dariah * @param dariah
*/ */
public RecordListDelivererIDIOM(boolean textgrid, boolean dariah) { public RecordListDelivererIDIOM(boolean textgrid, boolean dariah) {
super(textgrid, dariah); super(textgrid, dariah);
} }
...@@ -53,7 +61,7 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { ...@@ -53,7 +61,7 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract {
* @see info.textgrid.middleware.RecordListDelivererInterface#getRecords(java.lang.String, * @see info.textgrid.middleware.RecordListDelivererInterface#getRecords(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String) * java.lang.String, java.lang.String, java.lang.String)
*/ */
@Override /* @Override
public ListRecordsType getRecords(final String from, final String to, final String set, public ListRecordsType getRecords(final String from, final String to, final String set,
final String resumptionToken) { final String resumptionToken) {
...@@ -80,6 +88,7 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { ...@@ -80,6 +88,7 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract {
for (String artefactURI : artefactURIs) { for (String artefactURI : artefactURIs) {
RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false);
recordList.getRecord().add(idiomRecord.getRecordById(artefactURI).getRecord()); recordList.getRecord().add(idiomRecord.getRecordById(artefactURI).getRecord());
i++; i++;
} }
...@@ -93,8 +102,76 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { ...@@ -93,8 +102,76 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract {
} }
return recordList; return recordList;
} }*/
@Override
public ListRecordsType getRecords(final String from, final String to, final String set,
final String resumptionToken) {
System.out.println("BUFF");
ListRecordsType recordList = new ListRecordsType();
QueryBuilder recordFilterForClassicMayan;
QueryBuilder rangeQuery;
Queries queries = new Queries();
List<String> artefactURIs = queries.getArtefactList();;
rangeQuery = QueryBuilders.rangeQuery("created").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"));
SearchResponse scrollResp;
if (resumptionToken == null) {
scrollResp = OAI_ESClient.getOaiESClient()
.prepareSearch("textgrid-nonpublic")
.setScroll(new TimeValue(60000))
.setTypes(OAI_ESClient.getEsType())
.addFields("lastModified", "textgridUri", "project.id")
.setQuery(recordFilterForClassicMayan)
.setSize(30)
.execute()
.actionGet();
}else {
System.out.println("resumptionToken for res: " + resumptionToken);
scrollResp = OAI_ESClient.getOaiESClient().prepareSearchScroll(resumptionToken)
.setScroll(new TimeValue(60000)).execute().actionGet();
}
String scrollID = scrollResp.getScrollId();
long completeListSize = scrollResp.getHits().totalHits();
//System.out.println(completeListSize);
//System.out.println(completeListSize + " || " + artefactURIs.size());
if (completeListSize > 0) {
setFoundItems(true);
int i = 0;
//System.out.println("inside ");
for (SearchHit hit : scrollResp.getHits().getHits()) {
i++;
String textgridURI = hit.getFields().get("textgridUri").getValue().toString().replace(".0", "");
if(artefactURIs.contains(textgridURI)) {
RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false);
recordList.getRecord().add(idiomRecord.getRecordById(textgridURI).getRecord());
}
}
// Check the need for a resumption token!
System.out.println("resumptionToken: " + resumptionToken);
ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken(
completeListSize, resumptionToken, cursorCollector, scrollID, 30, i);
if (resTokenForResponse != null) {
recordList.setResumptionToken(resTokenForResponse);
}
}else {
setFoundItems(false);
}
return recordList;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
...@@ -120,4 +197,12 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { ...@@ -120,4 +197,12 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract {
this.oaiEsClient = oaiEsClient; this.oaiEsClient = oaiEsClient;
} }
public boolean isFoundItems() {
return foundItems;
}
public void setFoundItems(boolean foundItems) {
this.foundItems = foundItems;
}
} }
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