use of org.nextprot.api.solr.SearchResult in project nextprot-api by calipho-sib.
the class SolrServiceTest method shouldReturnResultsFromAdvancedQueryId.
@Ignore
// Explanation: SparqlQueryDictionary was not able to find the .rq files via getSparqlQueryList() method (because of classpath ???)
@Test
public void shouldReturnResultsFromAdvancedQueryId() throws Exception {
QueryRequest qr = new QueryRequest();
qr.setMode("advanced");
qr.setQuality("gold");
qr.setSparqlEngine("Jena");
qr.setQueryId("NXQ_00001");
Query q = queryBuilderService.buildQueryForSearch(qr, "entry");
SearchResult result = service.executeQuery(q);
assertEquals(5618, result.getFound());
}
use of org.nextprot.api.solr.SearchResult in project nextprot-api by calipho-sib.
the class SearchController method test.
@RequestMapping(value = "/user/{username}/protein-list/{list}/results", method = RequestMethod.GET)
public String test(@PathVariable("username") String username, @PathVariable("list") String listName, @RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "order", required = false) String order, @RequestParam(value = "start", required = false) String start, @RequestParam(value = "rows", required = false) String rows, @RequestParam(value = "filter", required = false) String filter, Model model) throws SearchQueryException {
UserProteinList proteinList = this.proteinListService.getUserProteinListByNameForUser(username, listName);
Set<String> accessions = proteinList.getAccessionNumbers();
String queryString = "id:" + (accessions.size() > 1 ? "(" + Joiner.on(" ").join(accessions) + ")" : accessions.iterator().next());
// SolrIndex index = this.configuration.getIndexByName("entry");
Query query = this.queryBuilderService.buildQueryForProteinLists("entry", queryString, "", sort, order, start, rows, filter);
SearchResult result = this.queryService.executeQuery(query);
model.addAttribute("result", result);
return "search";
}
use of org.nextprot.api.solr.SearchResult in project nextprot-api by calipho-sib.
the class SearchController method searchIds.
/**
* @param indexName
* @param queryRequest
* @param model
* @return
*/
@RequestMapping(value = "/search-ids/{index}", method = { RequestMethod.POST })
public String searchIds(@PathVariable("index") String indexName, @RequestBody QueryRequest queryRequest, Model model) {
if (this.queryService.checkAvailableIndex(indexName)) {
SearchResult result;
try {
Query query = null;
if ((queryRequest.getMode() != null) && queryRequest.getMode().equalsIgnoreCase("advanced")) {
Set<String> accessions = new HashSet<String>(sparqlService.findEntries(queryRequest.getSparql(), sparqlEndpoint.getUrl(), queryRequest.getSparqlTitle()));
String queryString = "id:" + (accessions.size() > 1 ? "(" + Joiner.on(" ").join(accessions) + ")" : accessions.iterator().next());
queryRequest.setQuery(queryString);
query = this.queryBuilderService.buildQueryForSearchIndexes(indexName, "pl_search", queryRequest);
} else {
query = this.queryBuilderService.buildQueryForSearchIndexes(indexName, "simple", queryRequest);
}
result = this.queryService.executeIdQuery(query);
model.addAttribute("SearchResult", SearchResult.class);
model.addAttribute("result", result);
} catch (SearchQueryException e) {
e.printStackTrace();
model.addAttribute("errormessage", e.getMessage());
return "exception";
}
}
return "search-ids";
}
use of org.nextprot.api.solr.SearchResult in project nextprot-api by calipho-sib.
the class EntryPublicationController method getEntryPublicationsByPubId.
@ApiMethod(path = "/entry-publications/pubid/{pubid}", verb = ApiVerb.GET, description = "Exports identified publication associated with neXtProt entries", produces = { MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "/entry-publications/pubid/{pubid}", method = { RequestMethod.GET })
@ResponseBody
public PublicationView getEntryPublicationsByPubId(@ApiPathParam(name = "pubid", description = "A publication id", allowedvalues = { "630194" }) @PathVariable("pubid") long publicationId, @ApiQueryParam(name = "limit", description = "The maximum number of returned results", allowedvalues = { "500" }) @RequestParam(value = "limit", required = false) String limit) {
List<EntryPublication> eps = publicationService.getEntryPublications(publicationId);
QueryRequest qr = new QueryRequest();
qr.setQuality("gold");
qr.setRows((limit != null) ? limit : "500");
PublicationView view = new PublicationView();
view.setPublication(publicationService.findPublicationById(publicationId));
// return the n first results
view.addEntryPublicationList(eps.stream().limit(Integer.parseInt(qr.getRows())).collect(Collectors.toList()));
qr.setEntryAccessionSet(view.getEntryPublicationMap().keySet());
Query q = queryBuilderService.buildQueryForSearch(qr, "entry");
try {
SearchResult searchResult = solrService.executeQuery(q);
view.setRelatedEntryCount(eps.size());
searchResult.getResults().forEach(result -> view.putEntrySolrResult(result));
} catch (SearchQueryException e) {
throw new NextProtException(e.getMessage());
}
return view;
}
use of org.nextprot.api.solr.SearchResult in project nextprot-api by calipho-sib.
the class ExpasySearchController method expasySearch.
@RequestMapping(value = "/expasy-search", method = { RequestMethod.POST, RequestMethod.GET })
public String expasySearch(@RequestParam String query, @RequestParam(required = false) String type, Model model, HttpServletResponse response) {
try {
QueryRequest qr = new QueryRequest();
qr.setQuality("gold-and-silver");
qr.setQuery(query);
Query bq = queryBuilderService.buildQueryForSearch(qr, "entry");
SearchResult result = queryService.executeQuery(bq);
model.addAttribute("count", result.getFound());
model.addAttribute("url", "https://www.nextprot.org/proteins/search?quality=gold-and-silver&query=" + query);
model.addAttribute("description", "Entries matching the query " + query + " in neXtProt");
} catch (NextProtException e) {
LOGGER.error(e.getLocalizedMessage());
e.printStackTrace();
response.setStatus(500);
model.addAttribute("count", -1);
model.addAttribute("url", "error message " + e.getMessage());
} catch (Exception e) {
LOGGER.error(e.getLocalizedMessage());
e.printStackTrace();
response.setStatus(500);
model.addAttribute("count", -1);
}
return "expasy-search";
}
Aggregations