Search in sources :

Example 11 with SearchResult

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());
}
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 12 with SearchResult

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";
}
Also used : Query(org.nextprot.api.solr.Query) UserQuery(org.nextprot.api.user.domain.UserQuery) UserProteinList(org.nextprot.api.user.domain.UserProteinList) SearchResult(org.nextprot.api.solr.SearchResult) AutocompleteSearchResult(org.nextprot.api.solr.AutocompleteSearchResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with SearchResult

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";
}
Also used : SearchQueryException(org.nextprot.api.commons.exception.SearchQueryException) Query(org.nextprot.api.solr.Query) UserQuery(org.nextprot.api.user.domain.UserQuery) SearchResult(org.nextprot.api.solr.SearchResult) AutocompleteSearchResult(org.nextprot.api.solr.AutocompleteSearchResult) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with SearchResult

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;
}
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 15 with SearchResult

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";
}
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

Query (org.nextprot.api.solr.Query)20 SearchResult (org.nextprot.api.solr.SearchResult)20 QueryRequest (org.nextprot.api.solr.QueryRequest)16 Test (org.junit.Test)14 WebUnitBaseTest (org.nextprot.api.web.dbunit.base.mvc.WebUnitBaseTest)14 NextProtException (org.nextprot.api.commons.exception.NextProtException)4 SearchQueryException (org.nextprot.api.commons.exception.SearchQueryException)4 UserQuery (org.nextprot.api.user.domain.UserQuery)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 HashSet (java.util.HashSet)2 AutocompleteSearchResult (org.nextprot.api.solr.AutocompleteSearchResult)2 ApiMethod (org.jsondoc.core.annotation.ApiMethod)1 Ignore (org.junit.Ignore)1 UserProteinList (org.nextprot.api.user.domain.UserProteinList)1