hot topics are determined according to the last 15 days articles
[pnews.git] / war / src / main / java / pnews / servlet / ArticleProvider.java
index 5d4959b..ba96fe3 100644 (file)
@@ -4,6 +4,7 @@ import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.time.Instant;
+import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -220,14 +221,17 @@ public class ArticleProvider {
                 final String FUNCTION_NAME = "getEntities";
                 EntityStat s;
                 List<EntityStat> stats;
+                Instant minInstant;
                 
                 LOG.entering(CLASS_NAME, FUNCTION_NAME, cat);
                 
                 articles = getArticles(cat, null);
                 
+                minInstant = Instant.now().minus(15, ChronoUnit.DAYS);
+                
                 entities = new HashMap<>();
-                for (Article a: articles) 
-                        if (a.getEntities() != null) {
+                for (Article a: articles)
+                        if (a.getPublicationDate().isAfter(minInstant) && a.getEntities() != null)
                                 for (String e: a.getEntities()) {
                                         s = entities.get(e);
                                         if (s == null) {
@@ -236,8 +240,7 @@ public class ArticleProvider {
                                         }
                                         s.increment();
                                 }                
-                        }
-                
+               
                 stats = new ArrayList<>(entities.values());
                 stats.sort(new Comparator<EntityStat>() {