fix #32
This commit is contained in:
parent
a5f01c4039
commit
70d3a3a6a0
1 changed files with 38 additions and 3 deletions
|
@ -22,13 +22,18 @@ import java.util.Map;
|
|||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import jp.sf.fess.FessSystemException;
|
||||
import jp.sf.fess.db.bsbhv.BsFavoriteLogBhv;
|
||||
import jp.sf.fess.db.cbean.ClickLogCB;
|
||||
import jp.sf.fess.db.exbhv.ClickLogBhv;
|
||||
import jp.sf.fess.db.exbhv.FavoriteLogBhv;
|
||||
import jp.sf.fess.db.exbhv.pmbean.FavoriteUrlCountPmb;
|
||||
import jp.sf.fess.db.exentity.customize.FavoriteUrlCount;
|
||||
import jp.sf.fess.ds.IndexUpdateCallback;
|
||||
import jp.sf.fess.helper.CrawlingSessionHelper;
|
||||
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
import org.codelibs.solr.lib.SolrGroup;
|
||||
import org.seasar.dbflute.cbean.ListResultBean;
|
||||
import org.seasar.framework.container.SingletonS2Container;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -43,8 +48,12 @@ public class IndexUpdateCallbackImpl implements IndexUpdateCallback {
|
|||
|
||||
public boolean clickCountEnabled = true;
|
||||
|
||||
public boolean favoriteCountEnabled = true;
|
||||
|
||||
public String clickCountField = "clickCount_i";
|
||||
|
||||
public String favoriteCountField = "favoriteCount_i";
|
||||
|
||||
protected volatile AtomicLong documentSize = new AtomicLong(0);
|
||||
|
||||
protected volatile long commitPerCount = 0;
|
||||
|
@ -64,8 +73,9 @@ public class IndexUpdateCallbackImpl implements IndexUpdateCallback {
|
|||
logger.debug("Adding " + dataMap);
|
||||
}
|
||||
|
||||
// TODO required check
|
||||
if (!dataMap.containsKey("url") || dataMap.get("url") == null) {
|
||||
// required check
|
||||
final Object urlObj = dataMap.get("url");
|
||||
if (urlObj == null) {
|
||||
throw new FessSystemException("url is null. dataMap=" + dataMap);
|
||||
}
|
||||
|
||||
|
@ -89,7 +99,11 @@ public class IndexUpdateCallbackImpl implements IndexUpdateCallback {
|
|||
}
|
||||
|
||||
if (clickCountEnabled) {
|
||||
addClickCountField(doc, dataMap.get("url").toString());
|
||||
addClickCountField(doc, urlObj.toString());
|
||||
}
|
||||
|
||||
if (favoriteCountEnabled) {
|
||||
addFavoriteCountField(doc, urlObj.toString());
|
||||
}
|
||||
|
||||
docList.add(doc);
|
||||
|
@ -170,6 +184,27 @@ public class IndexUpdateCallbackImpl implements IndexUpdateCallback {
|
|||
}
|
||||
}
|
||||
|
||||
protected void addFavoriteCountField(final SolrInputDocument doc,
|
||||
final String url) {
|
||||
final FavoriteLogBhv favoriteLogBhv = SingletonS2Container
|
||||
.getComponent(FavoriteLogBhv.class);
|
||||
final FavoriteUrlCountPmb pmb = new FavoriteUrlCountPmb();
|
||||
pmb.setUrl(url);
|
||||
final String path = BsFavoriteLogBhv.PATH_selectFavoriteUrlCount;
|
||||
final ListResultBean<FavoriteUrlCount> list = favoriteLogBhv
|
||||
.outsideSql().selectList(path, pmb, FavoriteUrlCount.class);
|
||||
|
||||
long count = 0;
|
||||
if (!list.isEmpty()) {
|
||||
count = list.get(0).getCnt().longValue();
|
||||
}
|
||||
|
||||
doc.addField(favoriteCountField, count);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Favorite Count: " + count + ", url: " + url);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDocumentSize() {
|
||||
return documentSize.get();
|
||||
|
|
Loading…
Add table
Reference in a new issue