Revision 49870
Added by Katerina Iatropoulou over 6 years ago
SolrResultSet.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.search.solr; |
2 | 2 |
|
3 | 3 |
import com.google.gson.Gson; |
4 |
import eu.dnetlib.api.data.SearchServiceException; |
|
4 | 5 |
import eu.dnetlib.data.search.transform.Transformer; |
5 | 6 |
import eu.dnetlib.data.search.transform.TransformerException; |
6 | 7 |
import eu.dnetlib.data.search.utils.solr.SolrResultSetOptionsUtil; |
7 | 8 |
import eu.dnetlib.data.search.utils.solr.SolrResultsFormatter; |
8 | 9 |
import eu.dnetlib.domain.EPR; |
9 |
import eu.dnetlib.functionality.cql.CqlTranslatorImpl; |
|
10 | 10 |
import gr.uoa.di.driver.enabling.resultset.ResultSet; |
11 | 11 |
import org.apache.commons.lang.StringEscapeUtils; |
12 | 12 |
import org.apache.log4j.Logger; |
... | ... | |
265 | 265 |
} |
266 | 266 |
|
267 | 267 |
|
268 |
public void cursorGet(Transformer transformer, OutputStream os) throws SolrServerException, IOException { |
|
269 |
|
|
268 |
public void cursorGet(Transformer transformer, OutputStream os) throws SolrServerException, IOException, SearchServiceException { |
|
270 | 269 |
queryOpts.add("start", "0"); |
270 |
queryOpts.add("rows", "0"); |
|
271 |
queryOpts.remove("rows"); |
|
271 | 272 |
queryOpts.add("rows", "500"); |
272 | 273 |
queryOpts.add("fl", "__result"); |
273 | 274 |
queryOpts.add("shards.tolerant","true"); |
... | ... | |
277 | 278 |
String cursorMark = "*"; |
278 | 279 |
String nextCursorMark = ""; |
279 | 280 |
|
281 |
int curs = 0; |
|
280 | 282 |
QueryResponse resp = solrClient.query(SolrParams.toSolrParams(queryOpts)); |
281 | 283 |
|
282 |
int curs = 0; |
|
283 | 284 |
while (!cursorMark.equals(nextCursorMark)) { |
284 |
logger.debug("QUERY OPTS: " + queryOpts.get("cursorMark")); |
|
285 | 285 |
resp = solrClient.query(SolrParams.toSolrParams(queryOpts)); |
286 |
logger.debug("TOTAL number " + resp.getResults().getNumFound()); |
|
287 |
logger.debug(resp.getNextCursorMark()); |
|
288 |
|
|
289 |
System.out.println("BEGIN"); |
|
290 |
System.out.println("cursor " + cursorMark); |
|
291 |
System.out.println("next cursor " + nextCursorMark); |
|
292 |
|
|
293 | 286 |
cursorMark = nextCursorMark; |
294 | 287 |
nextCursorMark = resp.getNextCursorMark(); |
295 | 288 |
|
... | ... | |
297 | 290 |
if (transformer != null) { |
298 | 291 |
String result = null; |
299 | 292 |
try { |
300 |
logger.debug(transformer.getClass()); |
|
301 | 293 |
result = transformer.transform(((ArrayList<String>) resp.getResults().get(i).get("__result")).get(0)); |
302 |
logger.debug("RESULT " + result); |
|
303 |
} catch (TransformerException e) { |
|
304 |
logger.error("Something went wrong.", e); |
|
294 |
|
|
295 |
} catch (TransformerException te) { |
|
296 |
logger.warn("Error transforming " + result, te); |
|
297 |
continue; |
|
305 | 298 |
} |
306 | 299 |
os.write(result.getBytes()); |
307 | 300 |
os.flush(); |
308 | 301 |
} |
309 | 302 |
} |
310 | 303 |
|
311 |
|
|
312 |
System.out.println("END"); |
|
313 |
System.out.println("cursor " + cursorMark); |
|
314 |
System.out.println("next cursor " + nextCursorMark); |
|
315 | 304 |
queryOpts.remove("cursorMark"); |
316 | 305 |
queryOpts.add("cursorMark", nextCursorMark); |
317 |
|
|
318 |
System.out.println("CURS " + curs); |
|
319 | 306 |
curs ++; |
307 |
} |
|
320 | 308 |
|
321 |
}
|
|
309 |
logger.debug("CURS " + curs);
|
|
322 | 310 |
} |
323 | 311 |
|
324 | 312 |
//TODO get rid of this as soon as Joomla portal is out |
... | ... | |
373 | 361 |
|
374 | 362 |
|
375 | 363 |
|
376 |
public static void main(String[] args) throws IOException, CQLParseException, SolrServerException { |
|
364 |
/* public static void main(String[] args) throws IOException, CQLParseException, SolrServerException {
|
|
377 | 365 |
CloudSolrServer solrClient = new CloudSolrServer("beta.solr.openaire.eu:9983"); |
378 | 366 |
solrClient.setDefaultCollection("DMF-index-openaire"); |
379 | 367 |
|
... | ... | |
471 | 459 |
|
472 | 460 |
System.out.println("max: " + max); |
473 | 461 |
*/ |
474 |
} |
|
462 |
// }
|
|
475 | 463 |
|
476 | 464 |
// @Override |
477 | 465 |
// public EPR getEpr() { |
Also available in: Unified diff
Added check for allowed number of returned results in cursor search