Search in sources :

Example 11 with QueryRequest

use of org.nextprot.api.solr.QueryRequest in project nextprot-api by calipho-sib.

the class SolrServiceTest method shouldReturnEmptyResultsFromEmptyAccessionSet.

@Test
public void shouldReturnEmptyResultsFromEmptyAccessionSet() throws Exception {
    QueryRequest qr = new QueryRequest();
    qr.setQuality("GOLD");
    qr.setEntryAccessionSet(new HashSet<>());
    Query q = queryBuilderService.buildQueryForSearch(qr, "entry");
    SearchResult result = service.executeQuery(q);
    assertEquals(0, result.getFound());
}
Also used : QueryRequest(org.nextprot.api.solr.QueryRequest) Query(org.nextprot.api.solr.Query) SearchResult(org.nextprot.api.solr.SearchResult) WebUnitBaseTest(org.nextprot.api.web.dbunit.base.mvc.WebUnitBaseTest) Test(org.junit.Test)

Example 12 with QueryRequest

use of org.nextprot.api.solr.QueryRequest 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());
}
Also used : QueryRequest(org.nextprot.api.solr.QueryRequest) Query(org.nextprot.api.solr.Query) SearchResult(org.nextprot.api.solr.SearchResult) Ignore(org.junit.Ignore) WebUnitBaseTest(org.nextprot.api.web.dbunit.base.mvc.WebUnitBaseTest) Test(org.junit.Test)

Example 13 with QueryRequest

use of org.nextprot.api.solr.QueryRequest 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;
}
Also used : SearchQueryException(org.nextprot.api.commons.exception.SearchQueryException) NextProtException(org.nextprot.api.commons.exception.NextProtException) QueryRequest(org.nextprot.api.solr.QueryRequest) Query(org.nextprot.api.solr.Query) SearchResult(org.nextprot.api.solr.SearchResult) ApiMethod(org.jsondoc.core.annotation.ApiMethod)

Example 14 with QueryRequest

use of org.nextprot.api.solr.QueryRequest in project nextprot-api by calipho-sib.

the class ExportController method buildQueryRequest.

private static QueryRequest buildQueryRequest(HttpServletRequest request, String query, String listId, String queryId, String sparql, String chromosome, String filter, String quality, String sort, String order) {
    QueryRequest qr = new QueryRequest();
    qr.setQuery(query);
    if (listId != null) {
        qr.setListId(listId);
    }
    if (sparql != null) {
        qr.setSparql(sparql);
    }
    if (chromosome != null) {
        qr.setChromosome(chromosome);
    }
    qr.setQueryId(queryId);
    qr.setRows("50");
    qr.setFilter(filter);
    qr.setSort(sort);
    qr.setOrder(order);
    qr.setQuality(quality);
    qr.setReferer(request.getHeader("referer"));
    qr.setUrl(request.getRequestURL().toString() + "?" + request.getQueryString());
    return qr;
}
Also used : QueryRequest(org.nextprot.api.solr.QueryRequest)

Example 15 with QueryRequest

use of org.nextprot.api.solr.QueryRequest 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";
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) QueryRequest(org.nextprot.api.solr.QueryRequest) Query(org.nextprot.api.solr.Query) SearchResult(org.nextprot.api.solr.SearchResult) NextProtException(org.nextprot.api.commons.exception.NextProtException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

QueryRequest (org.nextprot.api.solr.QueryRequest)21 Test (org.junit.Test)16 Query (org.nextprot.api.solr.Query)16 SearchResult (org.nextprot.api.solr.SearchResult)16 WebUnitBaseTest (org.nextprot.api.web.dbunit.base.mvc.WebUnitBaseTest)14 NextProtException (org.nextprot.api.commons.exception.NextProtException)2 WebIntegrationBaseTest (org.nextprot.api.web.dbunit.base.mvc.WebIntegrationBaseTest)2 HashSet (java.util.HashSet)1 ApiMethod (org.jsondoc.core.annotation.ApiMethod)1 Ignore (org.junit.Ignore)1 SearchQueryException (org.nextprot.api.commons.exception.SearchQueryException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1