indexToHit=info.live;
else
indexToHit=info.working;
Client client=new ESClient().getClient();
SearchResponse resp = null;
try {
SearchRequestBuilder srb = createRequest(client,qq);
srb.setIndices(indexToHit);
srb.addFields("inode","identifier");
if(limit>0)
srb.setSize(limit);
if(offset>0)
srb.setFrom(offset);
if(UtilMethods.isSet(sortBy)) {
if(sortBy.equals("random")) {
srb.addSort(SortBuilders.scriptSort("Math.random()", "number"));
}
else if(sortBy.endsWith("-order")) {
// related content ordering
int ind0=sortBy.indexOf('-'); // relationships tipicaly have a format stname1-stname2
int ind1=ind0>0 ? sortBy.indexOf('-',ind0+1) : -1;
if(ind1>0) {
String relName=sortBy.substring(0, ind1);
if((ind1+1)<sortBy.length()) {
String identifier=sortBy.substring(ind1+1, sortBy.length()-6);
if(UtilMethods.isSet(identifier)) {
srb.addSort(SortBuilders.scriptSort("related", "number")
.lang("native")
.param("relName", relName)
.param("identifier", identifier)
.order(SortOrder.ASC));
}
}
}
}
else if(!sortBy.startsWith("undefined") && !sortBy.startsWith("undefined_dotraw")) {
String[] sortbyArr=sortBy.split(",");
for (String sort : sortbyArr) {
String[] x=sort.trim().split(" ");
// srb.addSort(SortBuilders.fieldSort(x[0].toLowerCase()).order(x.length>1 && x[1].equalsIgnoreCase("desc") ?
// SortOrder.DESC : SortOrder.ASC));
// srb.addSort(SortBuilders.fieldSort(x[0].toLowerCase() + ".org").order(x.length>1 && x[1].equalsIgnoreCase("desc") ?
// SortOrder.DESC : SortOrder.ASC));
srb.addSort(SortBuilders.fieldSort(x[0].toLowerCase() + "_dotraw").order(x.length>1 && x[1].equalsIgnoreCase("desc") ?
SortOrder.DESC : SortOrder.ASC));
// srb.addSort(x[0].toLowerCase(),x.length>1 && x[1].equalsIgnoreCase("desc") ?
// SortOrder.DESC : SortOrder.ASC);
}
}
}
try{
resp = srb.execute().actionGet();
}catch (SearchPhaseExecutionException e) {
if(e.getMessage().contains("dotraw] in order to sort on")){
return new InternalSearchHits(InternalSearchHits.EMPTY,0,0);
}else{
throw e;
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return resp.getHits();
}