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 addFacet() 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) throws IOException {
ImmutableList<String> facetFields = ImmutableList.of(JOURNAL_FACET_FIELD, ARTICLE_TYPE_FACET_FIELD, AUTHOR_FACET_FIELD, SUBJECT_AREA_FACET_FIELD);
/* The journal and article type facets are special because we want
* to do an OR query with them, not an AND query. For example, a
* client wants to find articles in One OR in Medicine - an
* article can't be in both. For the rest of the facets the user
* wants to find content that matches ALL the conditions (AND) -
* not articles about neurons OR organisms, but articles about
* neurons AND organisms. This complicates the facets because we
* want to exclude the existing certain filter queries (fq) when
* calculating these facet. See
* https://lucene.apache.org/solr/guide/7_4/faceting.html#Faceting-TaggingandExcludingFilters
* for how this mechanism works.
*/
ArticleSearchQuery.Facet journalFacet = ArticleSearchQuery.Facet.builder().setField(JOURNAL_FACET_FIELD).setExcludeKey(JOURNAL_TAG).build();
ArticleSearchQuery.Facet articleTypeFacet = ArticleSearchQuery.Facet.builder().setField(ARTICLE_TYPE_FACET_FIELD).setExcludeKey(ARTICLE_TYPE_TAG).build();
ArticleSearchQuery facetQuery = query.toBuilder().setRows(0).setSortOrder(null).addFacet(journalFacet).addFacet(articleTypeFacet).addFacet(AUTHOR_FACET_FIELD).addFacet(SUBJECT_AREA_FACET_FIELD).build();
SolrSearchApi.Result results = solrSearchApi.search(facetQuery);
Map<String, Map<String, Integer>> facets = results.getFacets();
SearchFilter journalFilter = searchFilterFactory.createSearchFilter(facets.get(JOURNAL_FACET_FIELD), JOURNAL);
SearchFilter subjectAreaFilter = searchFilterFactory.createSearchFilter(facets.get(SUBJECT_AREA_FACET_FIELD), SUBJECT_AREA);
SearchFilter authorFilter = searchFilterFactory.createSearchFilter(facets.get(AUTHOR_FACET_FIELD), AUTHOR);
SearchFilter articleTypeFilter = searchFilterFactory.createSearchFilter(facets.get(ARTICLE_TYPE_FACET_FIELD), ARTICLE_TYPE);
ArticleSearchQuery sectionFacetQuery = query.toBuilder().addFacet(SECTION_FACET_FIELD).setRows(0).setSortOrder(null).setPartialSearch(true).build();
Map<String, Integer> sectionFacetResults = solrSearchApi.search(sectionFacetQuery).getFacets().get(SECTION_FACET_FIELD);
SearchFilter sectionFilter = searchFilterFactory.createSearchFilter(sectionFacetResults, SECTION);
// 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 HomeController method getRssFeedView.
/**
* Serves recent journal articles as XML to be read by an RSS reader
*
* @param site site the request originates from
* @return RSS view of recent articles for the specified site
* @throws IOException
*/
@RequestMapping(name = "homepageFeed", value = "/feed/{feedType:atom|rss}", method = RequestMethod.GET)
public ModelAndView getRssFeedView(@SiteParam Site site, @PathVariable String feedType) throws IOException {
ArticleSearchQuery query = ArticleSearchQuery.builder().setStart(0).setRows(getFeedLength(site)).setSortOrder(ArticleSearchQuery.SolrSortOrder.DATE_NEWEST_FIRST).setJournalKeys(ImmutableList.of(site.getJournalKey())).setDateRange(ArticleSearchQuery.SolrEnumeratedDateRange.ALL_TIME).setFields(ArticleSearchQuery.RSS_FIELDS).build();
SolrSearchApi.Result recentArticles = solrSearchApi.search(query);
ModelAndView mav = new ModelAndView();
FeedMetadataField.SITE.putInto(mav, site);
FeedMetadataField.FEED_INPUT.putInto(mav, recentArticles.getDocs());
mav.setView(FeedType.getView(articleFeedView, feedType));
return mav;
}
use of org.ambraproject.wombat.service.remote.ArticleSearchQuery in project wombat by PLOS.
the class SearchController method getSearchRssFeedView.
/**
* Performs a simple search and serves the result as XML to be read by an RSS reader
*
* @param request HttpServletRequest
* @param model model that will be passed to the template
* @param site site the request originates from
* @param params search parameters identical to the {@code search} method
* @return RSS view of articles returned by the search
* @throws IOException
*/
@RequestMapping(name = "searchFeed", value = "/search/feed/{feedType:atom|rss}", params = { "q" }, method = RequestMethod.GET)
public ModelAndView getSearchRssFeedView(HttpServletRequest request, Model model, @SiteParam Site site, @PathVariable String feedType, @RequestParam MultiValueMap<String, String> params) throws IOException {
CommonParams commonParams = modelCommonParams(request, model, site, params);
String queryString = params.getFirst("q");
ArticleSearchQuery query = commonParams.makeArticleSearchQueryBuilder().setQuery(queryString).setSimple(commonParams.isSimpleSearch(queryString)).setFields(ArticleSearchQuery.RSS_FIELDS).build();
SolrSearchApi.Result searchResults = solrSearchApi.search(query);
String feedTitle = new UrlParamBuilder().addAll(params).build().toString();
;
ModelAndView mav = new ModelAndView();
FeedMetadataField.SITE.putInto(mav, site);
FeedMetadataField.FEED_INPUT.putInto(mav, searchResults.getDocs());
FeedMetadataField.TITLE.putInto(mav, feedTitle);
mav.setView(FeedType.getView(articleFeedView, feedType));
return mav;
}
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) throws IOException {
CommonParams commonParams = modelCommonParams(request, model, site, params);
String queryString = params.getFirst("q");
ArticleSearchQuery query = commonParams.makeArticleSearchQueryBuilder().setQuery(queryString).setSimple(commonParams.isSimpleSearch(queryString)).build();
SolrSearchApi.Result searchResults;
try {
searchResults = solrSearchApi.search(query);
} catch (ServiceRequestException sre) {
model.addAttribute(isInvalidSolrRequest(queryString, sre) ? CANNOT_PARSE_QUERY_ERROR : UNKNOWN_QUERY_ERROR, true);
// not a valid search - report errors
return false;
}
addFiltersToModel(request, model, site, commonParams, query, searchResults);
model.addAttribute("searchResults", addArticleLinks(searchResults, request, site, siteSet));
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 ArticleArchiveServiceImpl method getDatesForJournal.
@Override
public Range<Date> getDatesForJournal(Site site) throws IOException, ParseException {
ArticleSearchQuery query = ArticleSearchQuery.builder().setRows(0).setStatsField("publication_date").setSortOrder(SolrSortOrder.RELEVANCE).setDateRange(SolrEnumeratedDateRange.ALL_TIME).setJournalKeys(ImmutableList.of(site.getJournalKey())).build();
SolrSearchApi.Result result = solrSearchApi.search(query);
Date minDate = result.getPublicationDateStats().getMin();
Date maxDate = result.getPublicationDateStats().getMax();
return Range.between(minDate, maxDate);
}
Aggregations