Search in sources :

Example 1 with SearchQueryException

use of org.nextprot.api.commons.exception.SearchQueryException in project nextprot-api by calipho-sib.

the class SearchServiceImpl method sortAccessions.

@Override
public List<String> sortAccessions(QueryRequest queryRequest, Set<String> accessions) {
    List<String> sortedAccessions = new ArrayList<String>();
    try {
        String queryString = "id:" + (accessions.size() > 1 ? "(" + Joiner.on(" ").join(accessions) + ")" : accessions.iterator().next());
        queryRequest.setQuery(queryString);
        Query query = queryBuilderService.buildQueryForSearchIndexes("entry", "pl_search", queryRequest);
        SearchResult result = this.solrService.executeQuery(query);
        List<Map<String, Object>> results = result.getResults();
        for (Map<String, Object> res : results) {
            String entry = (String) res.get("id");
            sortedAccessions.add(entry);
        }
    } catch (SearchQueryException e) {
        e.printStackTrace();
        throw new NextProtException("Error when retrieving accessions");
    }
    return sortedAccessions;
}
Also used : SearchQueryException(org.nextprot.api.commons.exception.SearchQueryException) NextProtException(org.nextprot.api.commons.exception.NextProtException) Query(org.nextprot.api.solr.Query) UserQuery(org.nextprot.api.user.domain.UserQuery) SearchResult(org.nextprot.api.solr.SearchResult)

Example 2 with SearchQueryException

use of org.nextprot.api.commons.exception.SearchQueryException 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 3 with SearchQueryException

use of org.nextprot.api.commons.exception.SearchQueryException 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 4 with SearchQueryException

use of org.nextprot.api.commons.exception.SearchQueryException in project nextprot-api by calipho-sib.

the class SolrServiceImpl method buildSolrQuery.

/**
 * Builds a SOLR Query according to the specified index configuration
 *
 * @param query
 * @param indexConfig
 * @return
 */
private SolrQuery buildSolrQuery(Query query, IndexConfiguration indexConfig) throws SearchQueryException {
    SolrQuery solrQuery = new SolrQuery();
    String queryString = indexConfig.buildQuery(query);
    String filter = query.getFilter();
    if (filter != null)
        queryString += " AND filters:" + filter;
    solrQuery.setQuery(queryString);
    solrQuery.setStart(query.getStart());
    solrQuery.setRows(query.getRows());
    solrQuery.setFields(indexConfig.getParameterQuery(IndexParameter.FL));
    solrQuery.set(IndexParameter.FL.name().toLowerCase(), indexConfig.getParameterQuery(IndexParameter.FL));
    solrQuery.set(IndexParameter.QF.name().toLowerCase(), indexConfig.getParameterQuery(IndexParameter.QF));
    solrQuery.set(IndexParameter.PF.name().toLowerCase(), indexConfig.getParameterQuery(IndexParameter.PF));
    solrQuery.set(IndexParameter.FN.name().toLowerCase(), indexConfig.getParameterQuery(IndexParameter.FN));
    solrQuery.set(IndexParameter.HI.name().toLowerCase(), indexConfig.getParameterQuery(IndexParameter.HI));
    Map<String, String> otherParameters = indexConfig.getOtherParameters();
    if (otherParameters != null)
        for (Entry<String, String> e : otherParameters.entrySet()) solrQuery.set(e.getKey(), e.getValue());
    String sortName = query.getSort();
    SortConfig sortConfig = null;
    if (sortName != null) {
        sortConfig = indexConfig.getSortConfig(sortName);
        if (sortConfig == null)
            throw new SearchQueryException("sort " + sortName + " does not exist");
    } else
        sortConfig = indexConfig.getDefaultSortConfiguration();
    if (query.getOrder() != null) {
        for (Pair<IndexField, ORDER> s : sortConfig.getSorting()) solrQuery.addSort(s.getFirst().getName(), query.getOrder());
    } else {
        for (Pair<IndexField, ORDER> s : sortConfig.getSorting()) solrQuery.addSort(s.getFirst().getName(), s.getSecond());
    }
    if (sortConfig.getBoost() != -1) {
        solrQuery.set("boost", "sum(1.0,product(div(log(informational_score),6.0),div(" + sortConfig.getBoost() + ",100.0)))");
    }
    return solrQuery;
}
Also used : ORDER(org.apache.solr.client.solrj.SolrQuery.ORDER) Entry(java.util.Map.Entry) SearchQueryException(org.nextprot.api.commons.exception.SearchQueryException) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 5 with SearchQueryException

use of org.nextprot.api.commons.exception.SearchQueryException in project nextprot-api by calipho-sib.

the class SearchServiceImpl method getAccessionsForSimple.

private Set<String> getAccessionsForSimple(QueryRequest queryRequest) {
    Set<String> set = new LinkedHashSet<>();
    try {
        Query query = this.queryBuilderService.buildQueryForSearchIndexes("entry", "simple", queryRequest);
        SearchResult results = solrService.executeIdQuery(query);
        for (Map<String, Object> f : results.getFoundFacets("id")) {
            String entry = (String) f.get("name");
            set.add(entry);
        }
    } catch (SearchQueryException e) {
        e.printStackTrace();
        throw new NextProtException("Error when retrieving accessions");
    }
    return set;
}
Also used : SearchQueryException(org.nextprot.api.commons.exception.SearchQueryException) NextProtException(org.nextprot.api.commons.exception.NextProtException) Query(org.nextprot.api.solr.Query) UserQuery(org.nextprot.api.user.domain.UserQuery) SearchResult(org.nextprot.api.solr.SearchResult)

Aggregations

SearchQueryException (org.nextprot.api.commons.exception.SearchQueryException)5 Query (org.nextprot.api.solr.Query)4 SearchResult (org.nextprot.api.solr.SearchResult)4 NextProtException (org.nextprot.api.commons.exception.NextProtException)3 UserQuery (org.nextprot.api.user.domain.UserQuery)3 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 ORDER (org.apache.solr.client.solrj.SolrQuery.ORDER)1 ApiMethod (org.jsondoc.core.annotation.ApiMethod)1 AutocompleteSearchResult (org.nextprot.api.solr.AutocompleteSearchResult)1 QueryRequest (org.nextprot.api.solr.QueryRequest)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1