예제 #1
0
 @Override
 public void exportArticles() {
   List<Article> articles =
       articleRepository.findArticlesForExport(new PageRequest(0, DEFAULT_SIZE));
   if (articles != null && !articles.isEmpty()) {
     LOG.info("Exported Items {}", articles.size());
     articles.stream().forEach(e -> e.setExported(true));
     articleRepository.save(articles);
     articleSearchRepository.save(articles);
   }
 }
예제 #2
0
  @Override
  public FacetedPage<Article> findArticlesByParameter(
      String parameter, Pageable pageable, SearchResult searchResult) {

    Assert.notNull(pageable);
    Assert.notNull(searchResult);

    // Sort
    SortBuilder sortBuilder = buildSortBuilder(searchResult.getSortOrder());

    // Facet builder for pharmacy names
    TermsFacetBuilder termsFacetBuilder = new TermsFacetBuilder("prices.pharmacy.name");
    termsFacetBuilder.field("prices.pharmacy.displayName");
    FacetRequest facetRequest = new NativeFacetRequest(termsFacetBuilder);

    // creates query for elastic search
    QueryBuilder queryBuilder;
    if (StringUtils.isBlank(parameter)) {
      queryBuilder = QueryBuilders.wildcardQuery("name", "*");
    } else {
      queryBuilder = QueryBuilders.wildcardQuery("name", "*" + parameter.toLowerCase() + "*");
    }

    // build filter for the elastic search
    FilterBuilder filterBuilder = null;
    if (CollectionUtils.isNotEmpty(searchResult.getPharmacies())) {
      filterBuilder = buildAndFilter("prices.pharmacy.displayName", searchResult.getPharmacies());
    }

    SearchQuery searchQuery =
        buildSearchQuery(queryBuilder, facetRequest, filterBuilder, pageable, sortBuilder);
    FacetedPage<Article> articles;
    try {
      articles = articleSearchRepository.search(searchQuery);
    } catch (ElasticsearchException ex) {
      LOG.warn("Search could not be executed {}", ex);
      articles = new FacetedPageImpl(new ArrayList<Article>());
    }

    return articles;
  }
예제 #3
0
 @Override
 public Page<Article> findArticlesByBestPrice(Pageable pageable) {
   Page<Article> page = articleSearchRepository.findAll(pageable);
   return page;
 }
예제 #4
0
 public Iterable<Article> findAll() {
   return articleSearchRepository.findAll();
 }