Search in sources :

Example 11 with ArticleSearchQuery

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);
}
Also used : ArticleSearchQuery(org.ambraproject.wombat.service.remote.ArticleSearchQuery) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat)

Example 12 with ArticleSearchQuery

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());
}
Also used : SolrArticleAdapter(org.ambraproject.wombat.service.SolrArticleAdapter) ArticleSearchQuery(org.ambraproject.wombat.service.remote.ArticleSearchQuery)

Example 13 with ArticleSearchQuery

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);
}
Also used : SolrSearchApi(org.ambraproject.wombat.service.remote.SolrSearchApi) ArticleSearchQuery(org.ambraproject.wombat.service.remote.ArticleSearchQuery) SearchFilter(org.ambraproject.wombat.model.SearchFilter) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 14 with ArticleSearchQuery

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);
    });
}
Also used : ArticleSearchQuery(org.ambraproject.wombat.service.remote.ArticleSearchQuery) CacheKey(org.ambraproject.wombat.util.CacheKey)

Example 15 with ArticleSearchQuery

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();
    });
}
Also used : SolrSearchApi(org.ambraproject.wombat.service.remote.SolrSearchApi) ArticleSearchQuery(org.ambraproject.wombat.service.remote.ArticleSearchQuery) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) CacheKey(org.ambraproject.wombat.util.CacheKey)

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