Search in sources :

Example 16 with ArticleSearchQuery

use of org.ambraproject.wombat.service.remote.ArticleSearchQuery in project wombat by PLOS.

the class DoiToJournalResolutionService method getJournalKeyFromDoi.

public String getJournalKeyFromDoi(String doi, Site site) throws IOException {
    ArticleSearchQuery explicitDoiSearchQuery = ArticleSearchQuery.builder().setSimple(false).setRows(1).setQuery("id:\"" + QueryParser.escape(doi) + "\"").build();
    List<SolrArticleAdapter> solrArticleAdapters = SolrArticleAdapter.unpackSolrQuery(solrSearchApi.search(explicitDoiSearchQuery));
    String journalKey = null;
    if (solrArticleAdapters.size() == 1) {
        journalKey = solrArticleAdapters.get(0).getJournalKey();
    }
    return journalKey;
}
Also used : ArticleSearchQuery(org.ambraproject.wombat.service.remote.ArticleSearchQuery)

Example 17 with ArticleSearchQuery

use of org.ambraproject.wombat.service.remote.ArticleSearchQuery in project wombat by PLOS.

the class SearchController method subjectAreaSearch.

/**
 * Set defaults and performs search for subject area landing page
 *
 * @param request HTTP request for browsing subject areas
 * @param model   model that will be passed to the template
 * @param site    site the request originates from
 * @param params  HTTP request params
 * @param subject the subject area to be search; return all articles if no subject area is provided
 * @throws IOException
 */
private void subjectAreaSearch(HttpServletRequest request, Model model, Site site, MultiValueMap<String, String> params, String subject) throws IOException {
    TaxonomyGraph taxonomyGraph = modelSubjectHierarchy(model, site, subject);
    String subjectName;
    if (Strings.isNullOrEmpty(subject)) {
        params.add("subject", "");
        subjectName = "All Subject Areas";
    } else {
        subject = subject.replace("_", " ");
        params.add("subject", subject);
        subjectName = taxonomyGraph.getName(subject);
    }
    model.addAttribute("subjectName", subjectName);
    // set defaults for subject area landing page
    if (isNullOrEmpty(params.get("resultsPerPage"))) {
        params.add("resultsPerPage", BROWSE_RESULTS_PER_PAGE);
    }
    if (isNullOrEmpty(params.get("sortOrder"))) {
        params.add("sortOrder", "DATE_NEWEST_FIRST");
    }
    if (isNullOrEmpty(params.get("filterJournals"))) {
        params.add("filterJournals", site.getJournalKey());
    }
    CommonParams commonParams = modelCommonParams(request, model, site, params);
    ArticleSearchQuery query = commonParams.makeArticleSearchQueryBuilder().setSimple(false).build();
    SolrSearchApi.Result searchResults = solrSearchApi.search(query);
    model.addAttribute("articles", SolrArticleAdapter.unpackSolrQuery(searchResults));
    model.addAttribute("searchResults", addArticleLinks(searchResults, request, site, siteSet));
    model.addAttribute("page", commonParams.getSingleParam(params, "page", "1"));
    model.addAttribute("journalKey", site.getKey());
    model.addAttribute("isBrowse", true);
    String authId = request.getRemoteUser();
    boolean subscribed = false;
    if (authId != null) {
        String subjectParam = Strings.isNullOrEmpty(subject) ? "" : subjectName;
        subscribed = alertService.isUserSubscribed(authId, site.getJournalKey(), subjectParam);
    }
    model.addAttribute("subscribed", subscribed);
}
Also used : SolrSearchApi(org.ambraproject.wombat.service.remote.SolrSearchApi) ArticleSearchQuery(org.ambraproject.wombat.service.remote.ArticleSearchQuery) TaxonomyGraph(org.ambraproject.wombat.model.TaxonomyGraph)

Aggregations

ArticleSearchQuery (org.ambraproject.wombat.service.remote.ArticleSearchQuery)17 SolrSearchApi (org.ambraproject.wombat.service.remote.SolrSearchApi)9 HashMap (java.util.HashMap)3 Map (java.util.Map)3 SearchFilter (org.ambraproject.wombat.model.SearchFilter)3 ServiceRequestException (org.ambraproject.wombat.service.remote.ServiceRequestException)2 CacheKey (org.ambraproject.wombat.util.CacheKey)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Site (org.ambraproject.wombat.config.site.Site)1