use of org.ambraproject.wombat.service.remote.ArticleSearchQuery in project wombat by PLOS.
the class ArticleArchiveServiceImpl method getArticleDoisPerMonth.
/**
* {@inheritDoc}
*/
@Override
public SolrSearchApi.Result getArticleDoisPerMonth(Site site, String year, String month, String cursor) throws IOException, ParseException {
Calendar startDate = Calendar.getInstance();
startDate.setTime(new SimpleDateFormat("MMMM").parse(month));
startDate.set(Calendar.YEAR, Integer.parseInt(year));
startDate.set(Calendar.DAY_OF_MONTH, 1);
Calendar endDate = (Calendar) startDate.clone();
endDate.add(Calendar.MONTH, 1);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
ArticleSearchQuery.SolrExplicitDateRange dateRange = new ArticleSearchQuery.SolrExplicitDateRange("Monthly Search", dateFormat.format(startDate.getTime()), dateFormat.format(endDate.getTime()));
ArticleSearchQuery query = ArticleSearchQuery.builder().setJournalKeys(ImmutableList.of(site.getJournalKey())).setRows(MAXIMUM_SOLR_RESULT_COUNT).setSortOrder(ArticleSearchQuery.SolrSortOrder.DATE_OLDEST_FIRST).setDateRange(dateRange).setCursor(cursor).build();
return solrSearchApi.search(query);
}
use of org.ambraproject.wombat.service.remote.ArticleSearchQuery in project wombat by PLOS.
the class BrowseController method populateAuthors.
private void populateAuthors(Map<String, Object> article, Site site) throws IOException {
ArticleSearchQuery query = SolrArticleAdapter.lookupArticlesByDoisQuery(ImmutableList.of((String) article.get("doi")));
List<SolrArticleAdapter> solrArticles = SolrArticleAdapter.unpackSolrQuery(solrSearchApi.search(query));
article.put("authors", solrArticles.size() > 0 ? solrArticles.get(0).getAuthors() : ImmutableList.of());
}
use of org.ambraproject.wombat.service.remote.ArticleSearchQuery in project wombat by PLOS.
the class SearchFilterServiceTest method testGetSearchFilters.
@Test
public void testGetSearchFilters() throws IOException {
SearchFilter mockFilter = mock(SearchFilter.class);
when(searchFilterFactory.createSearchFilter(any(), any())).thenReturn(mockFilter);
ArticleSearchQuery query = ArticleSearchQuery.builder().setQuery("blah").setSimple(true).build();
SolrSearchApi.Result result = mock(SolrSearchApi.Result.class);
Map<String, Map<String, Integer>> facetMap = mock(Map.class);
when(result.getFacets()).thenReturn(facetMap);
when(facetMap.get(any())).thenReturn(ImmutableMap.of());
when(solrSearchApi.search(any())).thenReturn(result);
ImmutableMap<String, SearchFilter> expected = ImmutableMap.of("subject_area", mockFilter, "journal", mockFilter, "article_type", mockFilter, "author", mockFilter, "section", mockFilter);
Map<String, SearchFilter> searchFilters = searchFilterService.getSearchFilters(query);
assertEquals(expected, searchFilters);
}
use of org.ambraproject.wombat.service.remote.ArticleSearchQuery in project wombat by PLOS.
the class BrowseTaxonomyServiceImpl method parseCategories.
/**
* {@inheritDoc}
*/
public TaxonomyGraph parseCategories(final String journalKey) throws IOException {
CacheKey cacheKey = CacheKey.create("categories", journalKey);
return CacheUtil.getOrCompute(cache, cacheKey, () -> {
ArticleSearchQuery query = ArticleSearchQuery.builder().addFacet("subject_hierarchy").setFacetLimit(-1).setJournalKeys(ImmutableList.of(journalKey)).setRows(0).build();
List<String> subjects = solrSearchApi.search(query).getFacets().get("subject_hierarchy").keySet().stream().collect(Collectors.toList());
return TaxonomyGraph.create(subjects);
});
}
use of org.ambraproject.wombat.service.remote.ArticleSearchQuery in project wombat by PLOS.
the class BrowseTaxonomyServiceImpl method getCounts.
/**
* {@inheritDoc}
*/
@Override
public Map<String, Integer> getCounts(TaxonomyGraph taxonomy, String journalKey) throws IOException {
CacheKey cacheKey = CacheKey.create("categoryCount", journalKey);
return CacheUtil.getOrCompute(cache, cacheKey, () -> {
ArticleSearchQuery query = ArticleSearchQuery.builder().addFacet("subject_facet").setFacetLimit(-1).setJournalKeys(ImmutableList.of(journalKey)).setRows(0).build();
SolrSearchApi.Result results = solrSearchApi.search(query);
ImmutableSortedMap.Builder<String, Integer> builder = ImmutableSortedMap.naturalOrder();
builder.putAll(results.getFacets().get("subject_facet"));
builder.put("ROOT", results.getNumFound());
return builder.build();
});
}
Aggregations