Revision 49850
Added by Katerina Iatropoulou over 6 years ago
modules/uoa-search/trunk/src/main/java/eu/dnetlib/data/search/solr/SolrResultSet.java | ||
---|---|---|
6 | 6 |
import eu.dnetlib.data.search.utils.solr.SolrResultSetOptionsUtil; |
7 | 7 |
import eu.dnetlib.data.search.utils.solr.SolrResultsFormatter; |
8 | 8 |
import eu.dnetlib.domain.EPR; |
9 |
import eu.dnetlib.functionality.cql.CqlTranslatorImpl; |
|
9 | 10 |
import gr.uoa.di.driver.enabling.resultset.ResultSet; |
10 | 11 |
import org.apache.commons.lang.StringEscapeUtils; |
11 | 12 |
import org.apache.log4j.Logger; |
... | ... | |
20 | 21 |
|
21 | 22 |
import javax.ws.rs.core.MediaType; |
22 | 23 |
import java.io.IOException; |
24 |
import java.io.OutputStream; |
|
23 | 25 |
import java.util.ArrayList; |
24 | 26 |
import java.util.HashMap; |
25 | 27 |
import java.util.List; |
... | ... | |
51 | 53 |
solrClient.setDefaultCollection(mdformat + "-" + layout + "-" + interpretation); |
52 | 54 |
} |
53 | 55 |
|
54 |
|
|
55 |
|
|
56 | 56 |
@Override |
57 | 57 |
public boolean isOpen() { |
58 | 58 |
return true; |
... | ... | |
145 | 145 |
return null; |
146 | 146 |
} |
147 | 147 |
|
148 |
@Override |
|
149 |
public EPR getEpr() { |
|
150 |
return null; |
|
151 |
} |
|
152 |
|
|
148 | 153 |
public Map<String,List<String>> newGet(int from, int to, String format, Transformer transformer, Transformer oldRefineTransformer) { |
149 | 154 |
List<String> refineSolrResults = new ArrayList<String>(); |
150 | 155 |
List<String> searchSolrResults = new ArrayList<String>(); |
... | ... | |
260 | 265 |
} |
261 | 266 |
|
262 | 267 |
|
268 |
public void cursorGet(Transformer transformer, OutputStream os) throws SolrServerException, IOException { |
|
269 |
|
|
270 |
queryOpts.add("start", "0"); |
|
271 |
queryOpts.add("rows", "500"); |
|
272 |
queryOpts.add("fl", "__result"); |
|
273 |
queryOpts.add("shards.tolerant","true"); |
|
274 |
queryOpts.add("cursorMark", "*"); |
|
275 |
queryOpts.add("sort", "__indexrecordidentifier asc"); |
|
276 |
|
|
277 |
String cursorMark = "*"; |
|
278 |
String nextCursorMark = ""; |
|
279 |
|
|
280 |
QueryResponse resp = solrClient.query(SolrParams.toSolrParams(queryOpts)); |
|
281 |
|
|
282 |
int curs = 0; |
|
283 |
while (!cursorMark.equals(nextCursorMark)) { |
|
284 |
logger.debug("QUERY OPTS: " + queryOpts.get("cursorMark")); |
|
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 |
cursorMark = nextCursorMark; |
|
294 |
nextCursorMark = resp.getNextCursorMark(); |
|
295 |
|
|
296 |
for (int i = 0; i < resp.getResults().size(); i++) { |
|
297 |
if (transformer != null) { |
|
298 |
String result = null; |
|
299 |
try { |
|
300 |
logger.debug(transformer.getClass()); |
|
301 |
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); |
|
305 |
} |
|
306 |
os.write(result.getBytes()); |
|
307 |
os.flush(); |
|
308 |
} |
|
309 |
} |
|
310 |
|
|
311 |
|
|
312 |
System.out.println("END"); |
|
313 |
System.out.println("cursor " + cursorMark); |
|
314 |
System.out.println("next cursor " + nextCursorMark); |
|
315 |
queryOpts.remove("cursorMark"); |
|
316 |
queryOpts.add("cursorMark", nextCursorMark); |
|
317 |
|
|
318 |
System.out.println("CURS " + curs); |
|
319 |
curs ++; |
|
320 |
|
|
321 |
} |
|
322 |
} |
|
323 |
|
|
263 | 324 |
//TODO get rid of this as soon as Joomla portal is out |
264 | 325 |
//Just copied and refactored the old one... |
265 | 326 |
@Deprecated |
... | ... | |
310 | 371 |
} |
311 | 372 |
} |
312 | 373 |
|
313 |
/* |
|
374 |
|
|
375 |
|
|
314 | 376 |
public static void main(String[] args) throws IOException, CQLParseException, SolrServerException { |
315 | 377 |
CloudSolrServer solrClient = new CloudSolrServer("beta.solr.openaire.eu:9983"); |
378 |
solrClient.setDefaultCollection("DMF-index-openaire"); |
|
379 |
|
|
316 | 380 |
NamedList<String> queryOpts = new NamedList<String>(); |
317 | 381 |
|
318 |
// queryOpts.add("q", new CqlTranslatorImpl().getTranslatedQuery("oaftype exact project").asLucene()); |
|
382 |
//q=*:*&start=0&rows=10&cursorMark=*&sort=dateofcollection asc |
|
383 |
queryOpts.add("q", new CqlTranslatorImpl().getTranslatedQuery("objIdentifier = acm_________::0002c24f82c295e925a2bdf7bbf49bfc").asLucene()); |
|
384 |
queryOpts.add("start", "0"); |
|
385 |
queryOpts.add("rows", "1"); |
|
386 |
queryOpts.add("fl", "__result"); |
|
387 |
queryOpts.add("shards.tolerant","true"); |
|
388 |
queryOpts.add("cursorMark", "*"); |
|
389 |
queryOpts.add("sort", "__indexrecordidentifier asc"); |
|
390 |
|
|
391 |
|
|
392 |
//queryOpts.add("q", new CqlTranslatorImpl().getTranslatedQuery("oaftype exact project").asLucene()); |
|
319 | 393 |
NamedList<String> extraOpts = new NamedList<String>(); |
320 | 394 |
|
395 |
QueryResponse resp = solrClient.query(SolrParams.toSolrParams(queryOpts)); |
|
396 |
|
|
397 |
System.out.println("results " + resp.getResults().size()); |
|
398 |
|
|
399 |
String cursorMark = "*"; |
|
400 |
String nextCursorMark = ""; |
|
401 |
|
|
402 |
int curs = 0; |
|
403 |
while (!cursorMark.equals(nextCursorMark)) { |
|
404 |
System.out.println("cursor " + cursorMark); |
|
405 |
System.out.println("next cursor " + nextCursorMark); |
|
406 |
cursorMark = nextCursorMark; |
|
407 |
for (int i = 0; i < resp.getResults().size(); i++) { |
|
408 |
String result = ((ArrayList<String>) resp.getResults().get(i).get("__result")).get(0); |
|
409 |
//System.out.println(result); |
|
410 |
resp = solrClient.query(SolrParams.toSolrParams(queryOpts)); |
|
411 |
} |
|
412 |
nextCursorMark = resp.getNextCursorMark(); |
|
413 |
queryOpts.add("cursorMark", nextCursorMark); |
|
414 |
|
|
415 |
System.out.println("CURS " + curs); |
|
416 |
curs ++; |
|
417 |
|
|
418 |
} |
|
419 |
|
|
420 |
|
|
421 |
//System.out.println((new CqlTranslatorImpl().getTranslatedQuery("objIdentifier = acm_________::0002c24f82c295e925a2bdf7bbf49bfc").asLucene())); |
|
422 |
|
|
423 |
|
|
424 |
|
|
321 | 425 |
//extraOpts.add("start", "1"); |
322 | 426 |
// extraOpts.add("rows", "10"); |
323 | 427 |
// extraOpts.addAll(queryOpts); |
324 | 428 |
|
325 |
queryOpts.add("facet", "true"); |
|
429 |
//queryOpts.add("facet", "true");
|
|
326 | 430 |
//TranslatedQuery translatedQuery = new CqlTranslatorImpl().getTranslatedQuery("oaftype=result sortBy resultdateofacceptance/sort.descending"); |
327 | 431 |
|
328 | 432 |
// queryOpts.add("q", "oaftype=project"); |
329 |
queryOpts.add("facet", "true"); |
|
330 |
queryOpts.add("facet.mincount", "1"); |
|
331 |
queryOpts.add("fq", "popularity"); |
|
433 |
//queryOpts.add("facet", "true");
|
|
434 |
//queryOpts.add("facet.mincount", "1");
|
|
435 |
//queryOpts.add("fq", "popularity");
|
|
332 | 436 |
|
333 | 437 |
|
334 | 438 |
|
... | ... | |
342 | 446 |
|
343 | 447 |
//queryOpts.add("sort", translatedQuery.getOptions().getSort().getField() + " " + translatedQuery.getOptions().getSort().getMode() ); |
344 | 448 |
|
345 |
solrClient.setDefaultCollection("DMF-index-openaire"); |
|
346 | 449 |
|
450 |
|
|
347 | 451 |
/* QueryResponse resp = null; |
348 | 452 |
synchronized (solrClient) { |
349 | 453 |
resp = solrClient.query(SolrParams.toSolrParams(extraOpts)); |
... | ... | |
367 | 471 |
|
368 | 472 |
System.out.println("max: " + max); |
369 | 473 |
*/ |
370 |
// }
|
|
474 |
} |
|
371 | 475 |
|
372 |
@Override |
|
373 |
public EPR getEpr() { |
|
374 |
return epr; |
|
375 |
}
|
|
476 |
// @Override
|
|
477 |
// public EPR getEpr() {
|
|
478 |
// return epr;
|
|
479 |
// }
|
|
376 | 480 |
} |
377 | 481 |
|
378 | 482 |
class BrowseField { |
modules/uoa-search/trunk/src/main/java/eu/dnetlib/data/search/app/SearchServiceImpl.java | ||
---|---|---|
25 | 25 |
import gr.uoa.di.driver.enabling.resultset.ResultSetFactory; |
26 | 26 |
import gr.uoa.di.driver.util.ServiceLocator; |
27 | 27 |
import org.apache.log4j.Logger; |
28 |
import org.apache.solr.client.solrj.SolrServerException; |
|
28 | 29 |
import org.w3c.dom.Document; |
29 | 30 |
import org.w3c.dom.Node; |
30 | 31 |
import org.xml.sax.InputSource; |
... | ... | |
35 | 36 |
import javax.xml.xpath.XPathConstants; |
36 | 37 |
import javax.xml.xpath.XPathExpression; |
37 | 38 |
import javax.xml.xpath.XPathFactory; |
39 |
import java.io.IOException; |
|
40 |
import java.io.OutputStream; |
|
38 | 41 |
import java.io.StringReader; |
39 | 42 |
import java.util.*; |
40 | 43 |
|
... | ... | |
266 | 269 |
return new SearchResult(query, Locale.getDefault().toString(), rs.size(), from, to, searchResults, browseResults, refinefields); |
267 | 270 |
} |
268 | 271 |
|
272 |
public void cursorSearch(String text, List<String> refinefields, List<String> fieldQueries, |
|
273 |
String format, Transformer transformer, OutputStream os) throws SearchServiceException { |
|
274 |
|
|
275 |
long startTime = System.nanoTime(); |
|
276 |
|
|
277 |
IndexService index = getIndexLocator().getService(); |
|
278 |
|
|
279 |
EPR epr = null; |
|
280 |
ResultSet<String> rs = null; |
|
281 |
|
|
282 |
List<String> browseResults = null; |
|
283 |
List<String> searchResults = null; |
|
284 |
|
|
285 |
String query = rewrite(text); |
|
286 |
enhanceFieldQueries(fieldQueries); |
|
287 |
logger.info("Performing cursor query " + query + "' and fields " + fieldQueries + " and refine " + refinefields); |
|
288 |
|
|
289 |
try { |
|
290 |
String eprQuery = createEprQuery(query, refinefields, fieldQueries); |
|
291 |
epr = index.getBrowsingStatistics(eprQuery, "all", mdFormat, indexLayout); |
|
292 |
|
|
293 |
if (epr == null) { |
|
294 |
throw new SearchServiceException("Something really strange happened there! Index returned null result set id."); |
|
295 |
} |
|
296 |
|
|
297 |
rs = rsFactory.createResultSet(epr); |
|
298 |
|
|
299 |
((SolrResultSet)rs).cursorGet(transformer,os); |
|
300 |
|
|
301 |
} catch (IndexServiceException ise) { |
|
302 |
logger.error("Error getting cursor results.", ise); |
|
303 |
throw new SearchServiceException("Error getting refine results.", ise); |
|
304 |
|
|
305 |
} catch (IOException ioe) { |
|
306 |
logger.error("Error getting cursor results.", ioe); |
|
307 |
throw new SearchServiceException("Error getting refine results.", ioe); |
|
308 |
|
|
309 |
} catch (SolrServerException sse) { |
|
310 |
logger.error("Error getting cursor results.", sse); |
|
311 |
throw new SearchServiceException("Error getting refine results.", sse); |
|
312 |
} |
|
313 |
|
|
314 |
long estimatedTime = System.nanoTime() - startTime; |
|
315 |
logger.info("Search time " + estimatedTime/1000000 + " milliseconds for cursor query " + query + |
|
316 |
" and fields " + fieldQueries + " and refine " + refinefields); |
|
317 |
|
|
318 |
rs.close(); |
|
319 |
} |
|
320 |
|
|
321 |
/* |
|
322 |
public OutputStream cursorSearch(String text, List<String> refinefields, List<String> fieldQueries) throws SearchServiceException, IOException, SolrServerException { |
|
323 |
|
|
324 |
//logger.info("newSearch > from: " + from + " to:" + to); |
|
325 |
long startTime = System.nanoTime(); |
|
326 |
|
|
327 |
IndexService index = getIndexLocator().getService(); |
|
328 |
|
|
329 |
EPR epr = null; |
|
330 |
ResultSet<String> rs = null; |
|
331 |
|
|
332 |
List<String> browseResults = null; |
|
333 |
List<String> searchResults = null; |
|
334 |
|
|
335 |
String query = rewrite(text); |
|
336 |
enhanceFieldQueries(fieldQueries); |
|
337 |
logger.info("Performing query " + query + "' and fields " + fieldQueries + " and refine " + refinefields); |
|
338 |
|
|
339 |
try { |
|
340 |
//TODO see parser and maybe delete! |
|
341 |
//query = new CQLParser().parse(query).toCQL(); |
|
342 |
String eprQuery = createEprQuery(query, refinefields, fieldQueries); |
|
343 |
|
|
344 |
epr = index.getBrowsingStatistics(eprQuery, "all", mdFormat, indexLayout); |
|
345 |
|
|
346 |
if (epr == null) { |
|
347 |
throw new SearchServiceException("Something really strange happened there! Index returned null result set id."); |
|
348 |
} |
|
349 |
|
|
350 |
//get the locale TODO do we need this? |
|
351 |
//String correctLocale = getCorrectLocale(locale); |
|
352 |
//StringTokenizer tokenizer = new StringTokenizer(correctLocale, "_"); |
|
353 |
//Locale requestLocale = new Locale(tokenizer.nextToken(), tokenizer.nextToken()); |
|
354 |
|
|
355 |
rs = rsFactory.createResultSet(epr); |
|
356 |
|
|
357 |
Map<String, List<String>> list = null; |
|
358 |
return ((SolrResultSet)rs).cursorGet(transformer); |
|
359 |
|
|
360 |
} catch (IndexServiceException ise) { |
|
361 |
logger.error("Error getting refine results.", ise); |
|
362 |
throw new SearchServiceException("Error getting refine results.", ise); |
|
363 |
|
|
364 |
} |
|
365 |
|
|
366 |
}*/ |
|
367 |
|
|
269 | 368 |
/* TODO: check if really needed |
270 | 369 |
private String getCorrectLocale(String givenLocaleName){ |
271 | 370 |
String correctLocale = null; |
modules/uoa-search/trunk/src/main/java/eu/dnetlib/data/search/web/api/SearchApiService.java | ||
---|---|---|
12 | 12 |
import org.springframework.stereotype.Component; |
13 | 13 |
|
14 | 14 |
import javax.servlet.http.HttpServletRequest; |
15 |
import javax.servlet.http.HttpServletResponse; |
|
15 | 16 |
import javax.ws.rs.*; |
16 | 17 |
import javax.ws.rs.core.Context; |
17 | 18 |
import javax.ws.rs.core.MediaType; |
18 | 19 |
import javax.ws.rs.core.Response; |
20 |
import javax.ws.rs.core.StreamingOutput; |
|
21 |
import java.io.*; |
|
22 |
import java.util.HashMap; |
|
19 | 23 |
import java.util.List; |
20 | 24 |
import java.util.Locale; |
25 |
import java.util.Map; |
|
26 |
import java.util.concurrent.TimeUnit; |
|
21 | 27 |
|
22 | 28 |
/** |
23 | 29 |
* Created by kiatrop on 2/6/2016. |
... | ... | |
560 | 566 |
return getCount(request, fullQuery, format, fieldQueries); |
561 | 567 |
} |
562 | 568 |
|
569 |
@GET |
|
570 |
@Path("/reports") |
|
571 |
@Produces(MediaType.TEXT_PLAIN) |
|
572 |
public Response fetchReport(@QueryParam("query") String query, |
|
573 |
@QueryParam("refine") @DefaultValue("false") boolean refine, |
|
574 |
@QueryParam("fields") final List<String> fields, |
|
575 |
@QueryParam("fq") final List<String> fieldQueries, |
|
576 |
@QueryParam("type") final String type, |
|
577 |
@QueryParam("format") final String format, |
|
578 |
@Context final HttpServletResponse response) throws Exception { |
|
579 |
|
|
580 |
RequestResponseHandler.Entity entity = extractEntity(type); |
|
581 |
Transformer transformer = extractTransformer(format, extractEntity(type)); |
|
582 |
boolean special = isSpecialFormat(format); |
|
583 |
String responseType = extractResponseFormat(format); |
|
584 |
|
|
585 |
StreamingOutput stream = new StreamingOutput() { |
|
586 |
@Override |
|
587 |
public void write(OutputStream os) throws IOException, WebApplicationException |
|
588 |
{ |
|
589 |
try { |
|
590 |
os.write(CSVResponseFormat.appendTitle(entity, special).getBytes()); |
|
591 |
searchService.cursorSearch(query, fields, fieldQueries, format, transformer, os); |
|
592 |
|
|
593 |
} catch (SearchServiceException sse) { |
|
594 |
os.write(("Fail to return report." + sse.getMessage()).getBytes()); |
|
595 |
logger.error("Fail to return report.", sse); |
|
596 |
} |
|
597 |
os.close(); |
|
598 |
} |
|
599 |
|
|
600 |
}; |
|
601 |
|
|
602 |
return Response.ok().entity(stream).type( MediaType.TEXT_PLAIN).build(); |
|
603 |
|
|
604 |
|
|
605 |
//q=*:*&start=0&rows=10&cursorMark=*&sort=dateofcollection asc |
|
606 |
/* try { |
|
607 |
queryOpts.add("q", new CqlTranslatorImpl().getTranslatedQuery("(oaftype exact result) and (resulttypeid exact publication)").asLucene()); |
|
608 |
|
|
609 |
} catch (CQLParseException e) { |
|
610 |
logger.error(e); |
|
611 |
} |
|
612 |
queryOpts.add("start", "0"); |
|
613 |
queryOpts.add("rows", "500"); |
|
614 |
queryOpts.add("fl", "__result"); |
|
615 |
queryOpts.add("shards.tolerant","true"); |
|
616 |
queryOpts.add("cursorMark", "*"); |
|
617 |
queryOpts.add("sort", "__indexrecordidentifier asc"); |
|
618 |
|
|
619 |
StreamingOutput stream = new StreamingOutput() { |
|
620 |
@Override |
|
621 |
public void write(OutputStream os) throws IOException, WebApplicationException |
|
622 |
{ |
|
623 |
int curs = 0; |
|
624 |
QueryResponse resp = null; |
|
625 |
|
|
626 |
String cursorMark = "*"; |
|
627 |
String nextCursorMark = ""; |
|
628 |
|
|
629 |
while (!cursorMark.equals(nextCursorMark)) { |
|
630 |
logger.debug("QUERY OPTS: " + queryOpts.get("cursorMark")); |
|
631 |
try { |
|
632 |
resp = solrClient.query(SolrParams.toSolrParams(queryOpts)); |
|
633 |
} catch (SolrServerException e) { |
|
634 |
logger.error("ERROROROROROROR!! ", e); |
|
635 |
e.printStackTrace(); |
|
636 |
} |
|
637 |
logger.debug("TOTAL number " + resp.getResults().getNumFound()); |
|
638 |
logger.debug(resp.getNextCursorMark()); |
|
639 |
|
|
640 |
System.out.println("BEGIN"); |
|
641 |
System.out.println("cursor " + cursorMark); |
|
642 |
System.out.println("next cursor " + nextCursorMark); |
|
643 |
|
|
644 |
cursorMark = nextCursorMark; |
|
645 |
nextCursorMark = resp.getNextCursorMark(); |
|
646 |
|
|
647 |
for (int i = 0; i < resp.getResults().size(); i++) { |
|
648 |
String result = ((ArrayList<String>) resp.getResults().get(i).get("__result")).get(0); |
|
649 |
os.write(result.getBytes()); |
|
650 |
os.flush(); |
|
651 |
} |
|
652 |
|
|
653 |
System.out.println("END"); |
|
654 |
System.out.println("cursor " + cursorMark); |
|
655 |
System.out.println("next cursor " + nextCursorMark); |
|
656 |
queryOpts.remove("cursorMark"); |
|
657 |
queryOpts.add("cursorMark", nextCursorMark); |
|
658 |
|
|
659 |
System.out.println("CURS " + curs); |
|
660 |
curs ++; |
|
661 |
|
|
662 |
} |
|
663 |
} |
|
664 |
}; |
|
665 |
|
|
666 |
//out.close(); |
|
667 |
|
|
668 |
time = System.currentTimeMillis() - time; |
|
669 |
System.out.println("Answer time " + time); |
|
670 |
//StreamingOutput output = response.getWriter(); |
|
671 |
return Response.ok().entity( stream ).type( MediaType.TEXT_PLAIN).build();*/ |
|
672 |
//return Response.status(Response.Status.OK).build(); |
|
673 |
} |
|
674 |
|
|
675 |
|
|
676 |
@GET |
|
677 |
@Path("/testreports") |
|
678 |
@Produces(MediaType.TEXT_PLAIN) |
|
679 |
public Response loadHierarchy(@PathParam( "pkPerson" ) String pkPerson) { |
|
680 |
final Map<Integer, String> people = new HashMap<>(); |
|
681 |
people.put(1, "Michael\n"); |
|
682 |
people.put(2, "Mark\n"); |
|
683 |
|
|
684 |
StreamingOutput stream = new StreamingOutput() { |
|
685 |
@Override |
|
686 |
public void write(OutputStream os) throws IOException, WebApplicationException |
|
687 |
{ |
|
688 |
|
|
689 |
while (true) { |
|
690 |
Writer writer = new BufferedWriter(new OutputStreamWriter(os)); |
|
691 |
writer.write(people.get(1)); |
|
692 |
writer.flush(); |
|
693 |
try { |
|
694 |
TimeUnit.SECONDS.sleep(1); |
|
695 |
} catch (InterruptedException e) { |
|
696 |
e.printStackTrace(); |
|
697 |
logger.error("ERROR.", e); |
|
698 |
} |
|
699 |
} |
|
700 |
|
|
701 |
/*while(true) { |
|
702 |
os.write(people.get(1).getBytes()); |
|
703 |
os.flush(); |
|
704 |
}*/ |
|
705 |
} |
|
706 |
}; |
|
707 |
|
|
708 |
return Response.ok().entity( stream ).type( MediaType.TEXT_PLAIN).build() ; |
|
709 |
} |
|
710 |
|
|
563 | 711 |
private String extractResponseFormat(String format) { |
564 | 712 |
if (format != null && !format.isEmpty()) { |
565 | 713 |
if (format.equalsIgnoreCase("json")) { |
... | ... | |
606 | 754 |
return null; |
607 | 755 |
} |
608 | 756 |
|
609 |
/* TODO: check if needed |
|
610 |
private String extractResponseType(String format) { |
|
611 |
return extractResponseFormat(format)+"; charset=UTF-8"; |
|
612 |
}*/ |
|
613 |
|
|
614 | 757 |
//TODO old way of creating query see if needed. |
615 | 758 |
/*private String buildSimpleSearchQuery(RequestResponseHandler.Entity entity, String keywords) { |
616 | 759 |
StringBuilder queryBuilder = new StringBuilder(); |
... | ... | |
659 | 802 |
} |
660 | 803 |
} |
661 | 804 |
|
662 |
/* private void enhanceQueryWithKeywords(StringBuilder queryBuilder, String keywords) { |
|
663 |
if ( keywords!= null && !keywords.isEmpty()) { |
|
664 |
CQLQueryBuilder.appendKeywords(queryBuilder, keywords); |
|
665 |
|
|
666 |
} else { |
|
667 |
CQLQueryBuilder.appendQuery(queryBuilder, "*"); |
|
668 |
} |
|
669 |
} |
|
670 |
*/ |
|
671 | 805 |
private void builtQueryKeywords(StringBuilder queryBuilder, String keywords) { |
672 | 806 |
if (keywords != null && !keywords.trim().isEmpty()) { |
673 | 807 |
CQLQueryBuilder.appendKeywords(queryBuilder, cleanKeywords(keywords)); |
... | ... | |
700 | 834 |
} |
701 | 835 |
} |
702 | 836 |
|
703 |
/* |
|
704 |
private void enhanceQueryWithEntityType(StringBuilder queryBuilder, RequestResponseHandler.Entity entity) { |
|
705 |
queryBuilder.append(entity.getQueryPrefix()); |
|
706 |
} |
|
707 |
*/ |
|
708 | 837 |
private void enhanceQueryWithEntityId(StringBuilder queryBuilder, RequestResponseHandler.Entity entity, String entityId) { |
709 | 838 |
if (queryBuilder.toString().isEmpty()) { |
710 | 839 |
CQLQueryBuilder.appendFieldTerm(queryBuilder, CQLQueryBuilder.Operator.NONE, "objidentifier", CQLQueryBuilder.Operator.EXACT, entityId); |
... | ... | |
718 | 847 |
|
719 | 848 |
} |
720 | 849 |
|
721 |
/* @Deprecated |
|
722 |
private String builtQueryByEntity(String query, RequestResponseHandler.Entity entity, List<String> fieldQueries) { |
|
723 |
StringBuilder queryBuilder = new StringBuilder(); |
|
724 |
//enhanceQueryWithEntityType(queryBuilder, entity); |
|
725 |
enhanceFieldQueryWithEntityType(entity, fieldQueries); |
|
726 |
|
|
727 |
if (query != null && !query.trim().isEmpty()) { |
|
728 |
CQLQueryBuilder.appendSimpleTerm(queryBuilder, CQLQueryBuilder.Operator.AND, "(" + query + ")"); |
|
729 |
} |
|
730 |
|
|
731 |
return queryBuilder.toString(); |
|
732 |
} |
|
733 |
*/ |
|
734 | 850 |
private Response getCount(HttpServletRequest request, String query, String format, List<String> fieldQueries) { |
735 | 851 |
String responseFormat = extractResponseFormat(format); |
736 | 852 |
|
modules/uoa-search/trunk/src/main/java/eu/dnetlib/data/search/web/api/SearchRequestController.java | ||
---|---|---|
47 | 47 |
|
48 | 48 |
private static final String PUBLICATION_BASIC_QUERY = "(oaftype exact result) and (resulttypeid exact publication)"; |
49 | 49 |
private static final String DATASET_BASIC_QUERY = "(oaftype exact result) and (resulttypeid exact dataset)"; |
50 |
private static final String SOFTWARE_BASIC_QUERY = "(oaftype exact result) and (resulttypeid exact software)"; |
|
50 | 51 |
private static final String PROJECT_BASIC_QUERY = "(oaftype exact project)"; |
51 | 52 |
|
52 | 53 |
private static final List<String> GLOBAL_PARAMETERS = Arrays.asList("page", "size", "format", "sortBy"); |
... | ... | |
182 | 183 |
@RequestMapping(value = "/api/publications", method = RequestMethod.GET) |
183 | 184 |
public void searchPublications(HttpServletRequest request, HttpServletResponse response) { |
184 | 185 |
|
186 |
long time = System.currentTimeMillis(); |
|
187 |
|
|
185 | 188 |
PrintWriter writer = null; |
186 | 189 |
|
187 | 190 |
try { |
... | ... | |
232 | 235 |
IOUtils.closeQuietly(writer); |
233 | 236 |
} |
234 | 237 |
} |
238 |
|
|
239 |
time = System.currentTimeMillis() - time; |
|
240 |
System.out.println("Answer old time " + time); |
|
235 | 241 |
} |
236 | 242 |
|
237 | 243 |
@RequestMapping(value = "/api/datasets", method = RequestMethod.GET) |
... | ... | |
291 | 297 |
|
292 | 298 |
} |
293 | 299 |
|
300 |
@RequestMapping(value = "/api/software", method = RequestMethod.GET) |
|
301 |
public void searchSoftware(HttpServletRequest request, HttpServletResponse response) { |
|
302 |
|
|
303 |
PrintWriter writer = null; |
|
304 |
|
|
305 |
try { |
|
306 |
writer = response.getWriter(); |
|
307 |
|
|
308 |
checkParameters(ListUtils.union(PUB_N_DATA_COMMON_PARAMETERS, DATA_PARAMETERS),request.getParameterMap()); |
|
309 |
|
|
310 |
int page = readParameter(request, "page", 1); |
|
311 |
int size = readParameter(request, "size", 10); |
|
312 |
checkRequestSize(page, size); |
|
313 |
|
|
314 |
String format = (request.getParameter("format") != null) ? request.getParameter("format") : "xml"; |
|
315 |
createResponseMeta(response, format); |
|
316 |
|
|
317 |
checkFormatParameter(PUB_N_DATASET_FORMATS, format); |
|
318 |
|
|
319 |
String model = request.getParameter("model"); |
|
320 |
checkModelParameter(PUB_N_DATASET_MODELS, model); |
|
321 |
String sTransformer = defineTransformer(model,format); |
|
322 |
|
|
323 |
Collection<String> referrers = readParameter(request,"referrer"); |
|
324 |
String newFormat = defineFormatter(model, format, false, referrers); |
|
325 |
|
|
326 |
String locale = request.getParameter("locale"); |
|
327 |
|
|
328 |
StringBuilder queryBuilder = new StringBuilder(); |
|
329 |
queryBuilder.append(SOFTWARE_BASIC_QUERY); |
|
330 |
|
|
331 |
ParameterQueryEnhancer.enhanceQueryWithFundingLevelParams(queryBuilder, request, vocabularyManager, isModelSygma(model)); |
|
332 |
ParameterQueryEnhancer.enhanceQueryWithOpenAIREIds(queryBuilder, request); |
|
333 |
ParameterQueryEnhancer.enhanceQueryWithMetadataKeywords(queryBuilder, request); |
|
334 |
ParameterQueryEnhancer.enhanceQueryWithFundingParams(queryBuilder, request); |
|
335 |
ParameterQueryEnhancer.enhanceQueryWithRelProjectParams(queryBuilder, request); |
|
336 |
ParameterQueryEnhancer.enhanceQueryWithAccessRights(queryBuilder, request); |
|
337 |
ParameterQueryEnhancer.enhanceQueryWithDate(queryBuilder, request); |
|
338 |
ParameterQueryEnhancer.enhanceQueryWithDoi(queryBuilder, request); |
|
339 |
|
|
340 |
ParameterQueryEnhancer.enhanceQueryWithResultsSortParameters(queryBuilder, request); |
|
341 |
|
|
342 |
FormattedSearchResult formattedSearchResult = searchService.search(queryBuilder.toString(),sTransformer, (newFormat!=null)?newFormat:format, locale, page, size); |
|
343 |
writer.append(formattedSearchResult.getFormattedResult()); |
|
344 |
|
|
345 |
} catch (Exception e) { |
|
346 |
logger.error("Fail to execute search.", e); |
|
347 |
createXmlErrorPage(writer, e); |
|
348 |
|
|
349 |
} finally { |
|
350 |
if (writer != null) { |
|
351 |
IOUtils.closeQuietly(writer); |
|
352 |
} |
|
353 |
} |
|
354 |
|
|
355 |
} |
|
356 |
|
|
294 | 357 |
@RequestMapping(value = "/api/projects", method = RequestMethod.GET) |
295 | 358 |
public void searchProjects(HttpServletRequest request, HttpServletResponse response) { |
296 | 359 |
|
... | ... | |
579 | 642 |
} |
580 | 643 |
} |
581 | 644 |
} |
645 |
|
|
646 |
/*public void test(HttpServletRequest request, HttpServletResponse response) throws IOException, SolrServerException { |
|
647 |
|
|
648 |
long time = System.currentTimeMillis(); |
|
649 |
|
|
650 |
CloudSolrServer solrClient = new CloudSolrServer("openaire-solr-beta.vls.icm.edu.pl:9983"); |
|
651 |
solrClient.setDefaultCollection("DMF-index-openaire"); |
|
652 |
|
|
653 |
response.setContentType("text/html"); |
|
654 |
ServletOutputStream out=response.getOutputStream(); |
|
655 |
|
|
656 |
NamedList<String> queryOpts = new NamedList<String>(); |
|
657 |
|
|
658 |
//q=*:*&start=0&rows=10&cursorMark=*&sort=dateofcollection asc |
|
659 |
try { |
|
660 |
queryOpts.add("q", new CqlTranslatorImpl().getTranslatedQuery("(oaftype exact result) and (resulttypeid exact publication) and (relfundershortname exact \"nhmrc_______::NHMRC||National Health and Medical Research Council (NHMRC)||NHMRC\")").asLucene()); |
|
661 |
|
|
662 |
} catch (CQLParseException e) { |
|
663 |
logger.error(e); |
|
664 |
} |
|
665 |
queryOpts.add("start", "0"); |
|
666 |
queryOpts.add("rows", "500"); |
|
667 |
queryOpts.add("fl", "__result"); |
|
668 |
queryOpts.add("shards.tolerant","true"); |
|
669 |
queryOpts.add("cursorMark", "*"); |
|
670 |
queryOpts.add("sort", "__indexrecordidentifier asc"); |
|
671 |
|
|
672 |
|
|
673 |
//queryOpts.add("q", new CqlTranslatorImpl().getTranslatedQuery("oaftype exact project").asLucene()); |
|
674 |
NamedList<String> extraOpts = new NamedList<String>(); |
|
675 |
|
|
676 |
QueryResponse resp = null; |
|
677 |
|
|
678 |
String cursorMark = "*"; |
|
679 |
String nextCursorMark = ""; |
|
680 |
|
|
681 |
//QueryResponse resp = solrClient.query(SolrParams.toSolrParams(queryOpts)); |
|
682 |
|
|
683 |
int curs = 0; |
|
684 |
while (!cursorMark.equals(nextCursorMark)) { |
|
685 |
logger.debug("QUERY OPTS: " + queryOpts.get("cursorMark")); |
|
686 |
resp = solrClient.query(SolrParams.toSolrParams(queryOpts)); |
|
687 |
logger.debug("TOTAL number " + resp.getResults().getNumFound()); |
|
688 |
logger.debug(resp.getNextCursorMark()); |
|
689 |
|
|
690 |
System.out.println("BEGIN"); |
|
691 |
System.out.println("cursor " + cursorMark); |
|
692 |
System.out.println("next cursor " + nextCursorMark); |
|
693 |
|
|
694 |
cursorMark = nextCursorMark; |
|
695 |
nextCursorMark = resp.getNextCursorMark(); |
|
696 |
|
|
697 |
for (int i = 0; i < resp.getResults().size(); i++) { |
|
698 |
String result = ((ArrayList<String>) resp.getResults().get(i).get("__result")).get(0); |
|
699 |
out.write(result.getBytes()); |
|
700 |
out.flush(); |
|
701 |
} |
|
702 |
|
|
703 |
System.out.println("END"); |
|
704 |
System.out.println("cursor " + cursorMark); |
|
705 |
System.out.println("next cursor " + nextCursorMark); |
|
706 |
queryOpts.remove("cursorMark"); |
|
707 |
queryOpts.add("cursorMark", nextCursorMark); |
|
708 |
|
|
709 |
System.out.println("CURS " + curs); |
|
710 |
curs ++; |
|
711 |
|
|
712 |
} |
|
713 |
|
|
714 |
out.close(); |
|
715 |
|
|
716 |
time = System.currentTimeMillis() - time; |
|
717 |
System.out.println("Answer time " + time); |
|
718 |
}*/ |
|
582 | 719 |
} |
Also available in: Unified diff
Added software in public API + first implementation for csv and html reports in new API