[Yanel-commits] rev 57543 - public/yanel/trunk/src/contributions/resources/personalized-content/src/java/org/wyona/yanel/impl/resources/boost

michi at wyona.com michi at wyona.com
Sun Mar 27 00:32:20 CET 2011


Author: michi
Date: 2011-03-27 00:32:20 +0100 (Sun, 27 Mar 2011)
New Revision: 57543

Modified:
   public/yanel/trunk/src/contributions/resources/personalized-content/src/java/org/wyona/yanel/impl/resources/boost/PersonalizedContentResource.java
Log:
last access implemented

Modified: public/yanel/trunk/src/contributions/resources/personalized-content/src/java/org/wyona/yanel/impl/resources/boost/PersonalizedContentResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/personalized-content/src/java/org/wyona/yanel/impl/resources/boost/PersonalizedContentResource.java	2011-03-26 14:36:40 UTC (rev 57542)
+++ public/yanel/trunk/src/contributions/resources/personalized-content/src/java/org/wyona/yanel/impl/resources/boost/PersonalizedContentResource.java	2011-03-26 23:32:20 UTC (rev 57543)
@@ -10,6 +10,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
+import java.util.Date;
 
 import org.apache.log4j.Logger;
 
@@ -40,11 +41,19 @@
 
         javax.servlet.http.Cookie cookie = org.wyona.yanel.servlet.AccessLog.getYanelAnalyticsCookie(getEnvironment().getRequest(), getEnvironment().getResponse());
         if (cookie != null) {
+            Date lastAccess = getLastAccess(cookie.getValue(), "www.yanel.org");
+            java.text.DateFormat df = new java.text.SimpleDateFormat("yyyyMMdd");
+
             doc.getDocumentElement().setAttributeNS(NAMESPACE, "cookie-id", cookie.getValue());
+            doc.getDocumentElement().setAttributeNS(NAMESPACE, "last-access", df.format(lastAccess));
+
             String[] userInterests = getUserInterests(cookie.getValue());
             if (userInterests != null && userInterests.length > 0) {
                 for (int k = 0; k < userInterests.length; k++) {
-                    org.wyona.yarep.core.Node[] nodes = getRealm().getRepository().getSearcher().search(userInterests[k]);
+                    String query = userInterests[k];
+                    String queryInclModDate = userInterests[k] + " AND mod_date:[" + df.format(lastAccess) + " TO " + df.format(new Date()) + "]"; // INFO: See http://lucene.apache.org/java/2_3_2/queryparsersyntax.html#Range%20Searches
+                    log.warn("DEBUG: Query: " + queryInclModDate);
+                    org.wyona.yarep.core.Node[] nodes = getRealm().getRepository().getSearcher().search(query);
                     if (nodes != null && nodes.length > 0) {
                         for (int i = 0; i < nodes.length; i++) {
                             org.w3c.dom.Element result = doc.createElementNS(NAMESPACE, "result");
@@ -70,6 +79,7 @@
 
     /**
      * Get user's interests (TODO: Use org.wyona.boost.client...)
+     * @param Unique cookie ID
      */
     private String[] getUserInterests(String cookieID) {
         String[] interests = new String[3];
@@ -78,4 +88,13 @@
         interests[2] = "Switzerland";
         return interests;
     }
+
+    /**
+     * Get user's last access (TODO: Use org.wyona.boost.client...)
+     * @param Unique cookie ID
+     */
+    private Date getLastAccess(String cookieID, String domain) throws Exception {
+        java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy.MM.dd");
+        return df.parse("2011.02.16");
+    }
 }



More information about the Yanel-commits mailing list