Search in sources :

Example 1 with ArticleSearchQuery

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

the class SearchController method performValidSearch.

private boolean performValidSearch(HttpServletRequest request, Model model, @SiteParam Site site, @RequestParam MultiValueMap<String, String> params, boolean isCsvExport) throws IOException {
    CommonParams commonParams = modelCommonParams(request, model, site, params, isCsvExport);
    String queryString = params.getFirst("q");
    ArticleSearchQuery.Builder query = ArticleSearchQuery.builder().setQuery(queryString).setSimple(commonParams.isSimpleSearch(queryString)).setIsCsvSearch(isCsvExport);
    commonParams.fill(query);
    ArticleSearchQuery queryObj = query.build();
    Map<?, ?> searchResults;
    try {
        searchResults = solrSearchApi.search(queryObj, site);
    } catch (ServiceRequestException sre) {
        model.addAttribute(isInvalidSolrRequest(queryString, sre) ? CANNOT_PARSE_QUERY_ERROR : UNKNOWN_QUERY_ERROR, true);
        // not a valid search - report errors
        return false;
    }
    if (!isCsvExport) {
        searchResults = solrSearchApi.addArticleLinks(searchResults, request, site, siteSet);
        addFiltersToModel(request, model, site, commonParams, queryObj, searchResults);
    }
    model.addAttribute("searchResults", searchResults);
    model.addAttribute("alertQuery", alertService.convertParamsToJson(params));
    // valid search - proceed to return results
    return true;
}
Also used : ArticleSearchQuery(org.ambraproject.wombat.service.remote.ArticleSearchQuery) ServiceRequestException(org.ambraproject.wombat.service.remote.ServiceRequestException)

Example 2 with ArticleSearchQuery

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

the class RecentArticleServiceImpl method getRecentArticlesByType.

private List<SolrArticleAdapter> getRecentArticlesByType(String articleType, List<String> articleTypesToExclude, List<String> journalKeys, SolrSearchApiImpl.SolrExplicitDateRange dateRange, Site site) throws IOException {
    ArticleSearchQuery recentArticleSearchQuery = ArticleSearchQuery.builder().setStart(0).setRows(MAXIMUM_SOLR_RESULT_COUNT).setSortOrder(SolrSearchApiImpl.SolrSortOrder.DATE_NEWEST_FIRST).setArticleTypes(ImmutableList.of(articleType)).setArticleTypesToExclude(articleTypesToExclude).setDateRange(dateRange).setJournalKeys(journalKeys).build();
    Map<String, ?> results = solrSearchApi.search(recentArticleSearchQuery, site);
    return SolrArticleAdapter.unpackSolrQuery(results);
}
Also used : ArticleSearchQuery(org.ambraproject.wombat.service.remote.ArticleSearchQuery)

Example 3 with ArticleSearchQuery

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

the class RecentArticleServiceImpl method getAllRecentArticles.

private List<SolrArticleAdapter> getAllRecentArticles(List<String> articleTypesToExclude, List<String> journalKeys, SolrSearchApiImpl.SolrExplicitDateRange dateRange, Site site) throws IOException {
    ArticleSearchQuery recentArticleSearchQuery = ArticleSearchQuery.builder().setStart(0).setRows(MAXIMUM_SOLR_RESULT_COUNT).setSortOrder(SolrSearchApiImpl.SolrSortOrder.DATE_NEWEST_FIRST).setArticleTypesToExclude(articleTypesToExclude).setDateRange(dateRange).setJournalKeys(journalKeys).build();
    Map<String, ?> results = solrSearchApi.search(recentArticleSearchQuery, site);
    return SolrArticleAdapter.unpackSolrQuery(results);
}
Also used : ArticleSearchQuery(org.ambraproject.wombat.service.remote.ArticleSearchQuery)

Example 4 with ArticleSearchQuery

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

the class SearchFilterService method getSearchFilters.

/**
 * Retrieves a map of search filters to be added to the model. The filters displayed will change
 * depending on the query executed, but the number and type of filters is constant.
 *
 * @param query Execute query to determine the search filter results.
 *              Must be set as faceted with the setFacet() method
 * @param urlParams search URL parameters that have been rebuilt from the ArticleSearchQuery object
 * @param site The site to perform the searches in
 * @return HashMap containing all applicable filters
 * @throws IOException
 */
public Map<String, SearchFilter> getSearchFilters(ArticleSearchQuery query, Multimap<String, String> urlParams, Site site) throws IOException {
    ArticleSearchQuery.Builder journalFacetQuery = ArticleSearchQuery.builder().setFacet(JOURNAL_FACET_FIELD).setQuery(query.getQuery().orElse(null)).setSimple(query.isSimple()).setArticleTypes(query.getArticleTypes()).setSubjects(query.getSubjects()).setAuthors(query.getAuthors()).setDateRange(query.getDateRange().orElse(null)).setSections(query.getSections());
    Map<?, ?> journalFacetResults = solrSearchApi.search(journalFacetQuery.build(), site);
    SearchFilter journalFilter = searchFilterFactory.createSearchFilter(journalFacetResults, JOURNAL, urlParams);
    ArticleSearchQuery.Builder subjectAreaFacetQuery = ArticleSearchQuery.builder().setFacet(SUBJECT_AREA_FACET_FIELD).setQuery(query.getQuery().orElse(null)).setSimple(query.isSimple()).setArticleTypes(query.getArticleTypes()).setAuthors(query.getAuthors()).setDateRange(query.getDateRange().orElse(null)).setJournalKeys(query.getJournalKeys()).setSections(query.getSections()).setSubjects(// pass the previously filtered subjects to narrow the results
    query.getSubjects());
    Map<?, ?> subjectAreaFacetResults = solrSearchApi.search(subjectAreaFacetQuery.build(), site);
    SearchFilter subjectAreaFilter = searchFilterFactory.createSearchFilter(subjectAreaFacetResults, SUBJECT_AREA, urlParams);
    ArticleSearchQuery.Builder authorFacetQuery = ArticleSearchQuery.builder().setFacet(AUTHOR_FACET).setQuery(query.getQuery().orElse(null)).setSimple(query.isSimple()).setJournalKeys(query.getJournalKeys()).setArticleTypes(query.getArticleTypes()).setDateRange(query.getDateRange().orElse(null)).setAuthors(// pass the previously filtered authors to narrow the results
    query.getAuthors()).setSubjects(query.getSubjects()).setSections(query.getSections());
    Map<?, ?> authorFacetResults = solrSearchApi.search(authorFacetQuery.build(), site);
    SearchFilter authorFilter = searchFilterFactory.createSearchFilter(authorFacetResults, AUTHOR, urlParams);
    ArticleSearchQuery.Builder articleTypeFacetQuery = ArticleSearchQuery.builder().setFacet(ARTICLE_TYPE_FACET).setQuery(query.getQuery().orElse(null)).setSimple(query.isSimple()).setDateRange(query.getDateRange().orElse(null)).setJournalKeys(query.getJournalKeys()).setSubjects(query.getSubjects()).setAuthors(query.getAuthors()).setSections(query.getSections());
    Map<?, ?> articleTypeFacetResults = solrSearchApi.search(articleTypeFacetQuery.build(), site);
    SearchFilter articleTypeFilter = searchFilterFactory.createSearchFilter(articleTypeFacetResults, ARTICLE_TYPE, urlParams);
    ArticleSearchQuery.Builder sectionFacetQuery = ArticleSearchQuery.builder().setFacet(SECTION_FACET).setIsPartialSearch(true).setQuery(query.getQuery().orElse(null)).setSimple(query.isSimple()).setDateRange(query.getDateRange().orElse(null)).setJournalKeys(query.getJournalKeys()).setSubjects(query.getSubjects()).setAuthors(query.getAuthors());
    Map<?, ?> sectionFacetResults = solrSearchApi.search(sectionFacetQuery.build(), site);
    SearchFilter sectionFilter = searchFilterFactory.createSearchFilter(sectionFacetResults, SECTION, urlParams);
    // TODO: add other filters here
    Map<String, SearchFilter> filters = new HashMap<>();
    filters.put(JOURNAL, journalFilter);
    filters.put(SUBJECT_AREA, subjectAreaFilter);
    filters.put(AUTHOR, authorFilter);
    filters.put(ARTICLE_TYPE, articleTypeFilter);
    filters.put(SECTION, sectionFilter);
    return filters;
}
Also used : ArticleSearchQuery(org.ambraproject.wombat.service.remote.ArticleSearchQuery) HashMap(java.util.HashMap) SearchFilter(org.ambraproject.wombat.model.SearchFilter)

Example 5 with ArticleSearchQuery

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

the class DoiToJournalResolutionService method getJournalKeysFromDois.

public List<String> getJournalKeysFromDois(List<String> dois, Site site) throws IOException {
    if (dois.isEmpty()) {
        return new ArrayList<String>();
    }
    List<String> quoted = dois.stream().map(doi -> {
        return "\"" + QueryParser.escape(doi) + "\"";
    }).collect(Collectors.toList());
    ArticleSearchQuery explicitDoiSearchQuery = ArticleSearchQuery.builder().setSimple(false).setRows(dois.size()).setQuery("id:(" + String.join(" OR ", quoted) + ")").setFields(ImmutableList.of("journal_key", "journal_name")).build();
    List<Map<String, Object>> docs = solrSearchApi.search(explicitDoiSearchQuery).getDocs();
    Map<String, String> keysMap = new HashMap<String, String>();
    docs.forEach(data -> {
        keysMap.put((String) data.get("id"), (String) data.get("journal_key"));
    });
    List<String> journalKeys = dois.stream().map(id -> {
        if (keysMap.containsKey(id)) {
            return keysMap.get(id);
        } else {
            return "";
        }
    }).collect(Collectors.toList());
    return journalKeys;
}
Also used : Logger(org.slf4j.Logger) ArticleSearchQuery(org.ambraproject.wombat.service.remote.ArticleSearchQuery) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) SolrSearchApi(org.ambraproject.wombat.service.remote.SolrSearchApi) Site(org.ambraproject.wombat.config.site.Site) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) Map(java.util.Map) ArticleSearchQuery(org.ambraproject.wombat.service.remote.ArticleSearchQuery) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

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