This commit is contained in:
Shinsuke Sugaya 2014-01-24 22:44:31 +09:00
parent 9da6b40d44
commit 6f3df3811b
5 changed files with 82 additions and 21 deletions

View file

@ -286,7 +286,8 @@ public class IndexAction {
public String go() throws IOException {
Map<String, Object> doc = null;
try {
doc = searchService.getDocument("docId:" + indexForm.docId);
doc = searchService.getDocument("docId:" + indexForm.docId,
new String[] { systemHelper.clickCountField });
} catch (final Exception e) {
logger.warn("Failed to request: " + indexForm.docId, e);
}
@ -318,6 +319,13 @@ public class IndexAction {
clickLog.setQueryRequestedTime(new Timestamp(Long
.parseLong(indexForm.rt)));
clickLog.setUserSessionId(userSessionId);
clickLog.setDocId(indexForm.docId);
long clickCount = 0;
final Object count = doc.get(systemHelper.clickCountField);
if (count instanceof Long) {
clickCount = ((Long) count).longValue();
}
clickLog.setClickCount(clickCount);
searchLogHelper.addClickLog(clickLog);
}
}

View file

@ -39,6 +39,10 @@ public class ClickLog extends BsClickLog {
private String userSessionId;
private String docId;
private long clickCount;
public String getUserSessionId() {
return userSessionId;
}
@ -64,13 +68,27 @@ public class ClickLog extends BsClickLog {
return null;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String getDocId() {
return docId;
}
public void setDocId(final String docId) {
this.docId = docId;
}
public long getClickCount() {
return clickCount;
}
public void setClickCount(final long clickCount) {
this.clickCount = clickCount;
}
@Override
public String toString() {
return "ClickLog [queryRequestedTime=" + queryRequestedTime
+ ", userSessionId=" + userSessionId + ", _id=" + _id
+ ", userSessionId=" + userSessionId + ", docId=" + docId
+ ", clickCount=" + clickCount + ", _id=" + _id
+ ", _searchId=" + _searchId + ", _url=" + _url
+ ", _requestedTime=" + _requestedTime + "]";
}

View file

@ -32,9 +32,12 @@ import jp.sf.fess.db.exbhv.UserInfoBhv;
import jp.sf.fess.db.exentity.ClickLog;
import jp.sf.fess.db.exentity.SearchLog;
import jp.sf.fess.db.exentity.UserInfo;
import jp.sf.fess.helper.DocumentHelper;
import jp.sf.fess.helper.SearchLogHelper;
import jp.sf.fess.helper.SystemHelper;
import jp.sf.fess.service.SearchLogService;
import jp.sf.fess.service.UserInfoService;
import jp.sf.fess.util.ComponentUtil;
import jp.sf.fess.util.FessBeans;
import org.seasar.framework.container.SingletonS2Container;
@ -139,25 +142,57 @@ public class SearchLogHelperImpl extends SearchLogHelper {
@Override
protected void processClickLogQueue(final Queue<ClickLog> queue) {
final Map<String, Long> clickCountMap = new HashMap<String, Long>();
final List<ClickLog> clickLogList = new ArrayList<ClickLog>();
for (final ClickLog clickLog : queue) {
final SearchLogCB cb = new SearchLogCB();
cb.query().setRequestedTime_Equal(clickLog.getQueryRequestedTime());
cb.query().setUserSessionId_Equal(clickLog.getUserSessionId());
final SearchLogBhv searchLogBhv = SingletonS2Container
.getComponent(SearchLogBhv.class);
final SearchLog entity = searchLogBhv.selectEntity(cb);
if (entity != null) {
clickLog.setSearchId(entity.getId());
clickLogList.add(clickLog);
} else {
logger.warn("Not Found[ClickLog]: " + clickLog);
try {
final SearchLogCB cb = new SearchLogCB();
cb.query().setRequestedTime_Equal(
clickLog.getQueryRequestedTime());
cb.query().setUserSessionId_Equal(clickLog.getUserSessionId());
final SearchLogBhv searchLogBhv = SingletonS2Container
.getComponent(SearchLogBhv.class);
final SearchLog entity = searchLogBhv.selectEntity(cb);
if (entity != null) {
clickLog.setSearchId(entity.getId());
clickLogList.add(clickLog);
} else {
logger.warn("Not Found[ClickLog]: " + clickLog);
}
final String docId = clickLog.getDocId();
Long countObj = clickCountMap.get(docId);
final long clickCount = clickLog.getClickCount();
if (countObj == null) {
countObj = Long.valueOf(clickCount);
} else {
countObj = Math.max(countObj.longValue(), clickCount) + 1;
}
clickCountMap.put(docId, countObj);
} catch (final Exception e) {
logger.warn("Failed to process: " + clickLog, e);
}
}
if (!clickLogList.isEmpty()) {
final ClickLogBhv clickLogBhv = SingletonS2Container
.getComponent(ClickLogBhv.class);
clickLogBhv.batchInsert(clickLogList);
try {
final ClickLogBhv clickLogBhv = SingletonS2Container
.getComponent(ClickLogBhv.class);
clickLogBhv.batchInsert(clickLogList);
} catch (final Exception e) {
logger.warn("Failed to insert: " + clickLogList, e);
}
}
final DocumentHelper documentHelper = ComponentUtil.getDocumentHelper();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
for (final Map.Entry<String, Long> entry : clickCountMap.entrySet()) {
try {
documentHelper.update(entry.getKey(),
systemHelper.clickCountField, entry.getValue() + 1);
} catch (final Exception e) {
logger.warn("Failed to update a clickCount(" + entry.getValue()
+ ") for " + entry.getKey(), e);
}
}
}
}

View file

@ -355,7 +355,7 @@ labels.search_result_created=Registered:
labels.search_result_lastModified=Last Modified:
labels.search_result_favorite=Vote it ({0})
labels.search_result_favorited=Voted ({0})
labels.search_click_count=Click ({0})
labels.search_click_count=Click: {0}
labels.search_result_more=more..
label.facet_label_title=Label

View file

@ -355,7 +355,7 @@ labels.search_result_created=\u767b\u9332\u65e5\u6642:
labels.search_result_lastModified=\u66f4\u65b0\u65e5\u6642:
labels.search_result_favorite=1\u7968\u5165\u308c\u308b ({0})
labels.search_result_favorited=\u6295\u7968\u6e08\u307f ({0})
labels.search_click_count=\u30af\u30ea\u30c3\u30af\u6570 ({0})
labels.search_click_count=\u30af\u30ea\u30c3\u30af\u6570: {0}
labels.search_result_more=\u8a73\u7d30..
label.facet_label_title=\u30e9\u30d9\u30eb