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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations