[Yanel-commits] rev 57556 - public/yanel/trunk/src/contributions/resources/personalized-content/src/java/org/wyona/yanel/impl/resources/boost
michi at wyona.com
michi at wyona.com
Mon Mar 28 14:41:30 CEST 2011
Author: michi
Date: 2011-03-28 14:41:29 +0200 (Mon, 28 Mar 2011)
New Revision: 57556
Modified:
public/yanel/trunk/src/contributions/resources/personalized-content/src/java/org/wyona/yanel/impl/resources/boost/PersonalizedContentResource.java
Log:
split into since and before last access
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-28 12:24:51 UTC (rev 57555)
+++ public/yanel/trunk/src/contributions/resources/personalized-content/src/java/org/wyona/yanel/impl/resources/boost/PersonalizedContentResource.java 2011-03-28 12:41:29 UTC (rev 57556)
@@ -31,12 +31,13 @@
final String NAMESPACE = "http://www.wyona.org/yanel/boost/1.0";
org.w3c.dom.Document doc = XMLHelper.createDocument(NAMESPACE, "personalized-content");
+ org.w3c.dom.Element rootEl = doc.getDocumentElement();
String username = getEnvironment().getIdentity().getUsername();
if (username != null) {
- doc.getDocumentElement().setAttributeNS(NAMESPACE, "user-id", username);
+ rootEl.setAttributeNS(NAMESPACE, "user-id", username);
} else {
- doc.getDocumentElement().appendChild(doc.createElementNS(NAMESPACE, "no-username-yet"));
+ rootEl.appendChild(doc.createElementNS(NAMESPACE, "no-username-yet"));
}
javax.servlet.http.Cookie cookie = org.wyona.yanel.servlet.AccessLog.getYanelAnalyticsCookie(getEnvironment().getRequest(), getEnvironment().getResponse());
@@ -44,37 +45,61 @@
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));
+ rootEl.setAttributeNS(NAMESPACE, "cookie-id", cookie.getValue());
+ rootEl.setAttributeNS(NAMESPACE, "last-access", df.format(lastAccess));
+ org.w3c.dom.Element sinceLastAccessEl = doc.createElementNS(NAMESPACE, "since-last-access");
+ rootEl.appendChild(sinceLastAccessEl);
+
+ org.w3c.dom.Element beforeLastAccessEl = doc.createElementNS(NAMESPACE, "before-last-access");
+ rootEl.appendChild(beforeLastAccessEl);
+
String[] userInterests = getUserInterests(cookie.getValue());
if (userInterests != null && userInterests.length > 0) {
for (int k = 0; k < userInterests.length; 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
String queryInclModDate = userInterests[k] + " AND yarep_lastModified:[" + lastAccess.getTime() + " TO " + new Date().getTime() + "]"; // 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);
- org.wyona.yarep.core.Node[] nodes = getRealm().getRepository().getSearcher().search(queryInclModDate);
- if (nodes != null && nodes.length > 0) {
- for (int i = 0; i < nodes.length; i++) {
+
+ org.wyona.yarep.core.Node[] nodesInclModDate = getRealm().getRepository().getSearcher().search(queryInclModDate);
+
+ if (nodesInclModDate != null && nodesInclModDate.length > 0) {
+ for (int i = 0; i < nodesInclModDate.length; i++) {
org.w3c.dom.Element result = doc.createElementNS(NAMESPACE, "result");
- result.setAttributeNS(NAMESPACE, "node-path", nodes[i].getPath());
- result.setAttributeNS(NAMESPACE, "node-last-modified", "" + new Date(nodes[i].getLastModified()));
+ result.setAttributeNS(NAMESPACE, "node-path", nodesInclModDate[i].getPath());
+ result.setAttributeNS(NAMESPACE, "node-last-modified", "" + new Date(nodesInclModDate[i].getLastModified()));
result.setAttributeNS(NAMESPACE, "interest", userInterests[k]);
- doc.getDocumentElement().appendChild(result);
+ sinceLastAccessEl.appendChild(result);
}
} else {
org.w3c.dom.Element noResults = doc.createElementNS(NAMESPACE, "no-results");
noResults.setAttributeNS(NAMESPACE, "interest", userInterests[k]);
- doc.getDocumentElement().appendChild(noResults);
+ sinceLastAccessEl.appendChild(noResults);
}
+
+ String query = userInterests[k];
+ 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++) {
+ if (nodes[i].getLastModified() < lastAccess.getTime()) {
+ org.w3c.dom.Element result = doc.createElementNS(NAMESPACE, "result");
+ result.setAttributeNS(NAMESPACE, "node-path", nodes[i].getPath());
+ result.setAttributeNS(NAMESPACE, "node-last-modified", "" + new Date(nodes[i].getLastModified()));
+ result.setAttributeNS(NAMESPACE, "interest", userInterests[k]);
+ beforeLastAccessEl.appendChild(result);
+ }
+ }
+ } else {
+ org.w3c.dom.Element noResults = doc.createElementNS(NAMESPACE, "no-results");
+ noResults.setAttributeNS(NAMESPACE, "interest", userInterests[k]);
+ beforeLastAccessEl.appendChild(noResults);
+ }
}
} else {
- doc.getDocumentElement().appendChild(doc.createElementNS(NAMESPACE, "no-user-interests"));
+ rootEl.appendChild(doc.createElementNS(NAMESPACE, "no-user-interests"));
}
} else {
- doc.getDocumentElement().appendChild(doc.createElementNS(NAMESPACE, "no-cookie-yet"));
+ rootEl.appendChild(doc.createElementNS(NAMESPACE, "no-cookie-yet"));
}
return XMLHelper.getInputStream(doc, false, false, null);
@@ -84,7 +109,7 @@
* Get user's interests (TODO: Use org.wyona.boost.client...)
* @param Unique cookie ID
*/
- private String[] getUserInterests(String cookieID) {
+ protected String[] getUserInterests(String cookieID) {
String[] interests = new String[3];
interests[0] = "Lucene";
interests[1] = "OSGi";
@@ -96,7 +121,7 @@
* Get user's last access (TODO: Use org.wyona.boost.client...)
* @param Unique cookie ID
*/
- private Date getLastAccess(String cookieID, String domain) throws Exception {
+ protected 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