fix #224
This commit is contained in:
parent
2b4d9d8a18
commit
394dada5cb
2 changed files with 31 additions and 2 deletions
|
@ -240,6 +240,8 @@ public class Constants extends CoreLibConstants {
|
|||
|
||||
public static final String SESSION_ID = "sessionId";
|
||||
|
||||
public static final String CRAWLING_SESSION_ID = "crawlingSessionId";
|
||||
|
||||
public static final String INDEXING_TARGET = "indexingTarget";
|
||||
|
||||
public static final String DIGEST_PREFIX = "...";
|
||||
|
|
|
@ -33,7 +33,9 @@ import jp.sf.fess.ds.IndexUpdateCallback;
|
|||
import jp.sf.fess.service.DataCrawlingConfigService;
|
||||
import jp.sf.fess.util.ComponentUtil;
|
||||
|
||||
import org.apache.solr.client.solrj.util.ClientUtils;
|
||||
import org.codelibs.core.util.DynamicProperties;
|
||||
import org.codelibs.core.util.StringUtil;
|
||||
import org.codelibs.solr.lib.SolrGroup;
|
||||
import org.seasar.framework.container.SingletonS2Container;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -131,7 +133,7 @@ public class DataIndexHelper implements Serializable {
|
|||
sessionIdList.add(sid);
|
||||
|
||||
initParamMap.put(Constants.SESSION_ID, sessionId);
|
||||
initParamMap.put("crawlingSessionId", sid);
|
||||
initParamMap.put(Constants.CRAWLING_SESSION_ID, sid);
|
||||
|
||||
final DataCrawlingThread dataCrawlingThread = new DataCrawlingThread(
|
||||
dataCrawlingConfig, indexUpdateCallback, initParamMap);
|
||||
|
@ -273,12 +275,37 @@ public class DataIndexHelper implements Serializable {
|
|||
} catch (final Exception e) {
|
||||
logger.error("Failed to process a data crawling: "
|
||||
+ dataCrawlingConfig.getName(), e);
|
||||
} finally {
|
||||
deleteOldDocs();
|
||||
}
|
||||
}
|
||||
running = false;
|
||||
finished = true;
|
||||
}
|
||||
|
||||
private void deleteOldDocs() {
|
||||
final String sessionId = initParamMap.get(Constants.SESSION_ID);
|
||||
if (StringUtil.isBlank(sessionId)) {
|
||||
logger.warn("Invalid sessionId at " + dataCrawlingConfig);
|
||||
return;
|
||||
}
|
||||
final FieldHelper fieldHelper = ComponentUtil.getFieldHelper();
|
||||
final StringBuilder buf = new StringBuilder(100);
|
||||
buf.append(fieldHelper.configIdField).append(':')
|
||||
.append(dataCrawlingConfig.getConfigId());
|
||||
buf.append(" NOT ");
|
||||
buf.append(fieldHelper.segmentField).append(':')
|
||||
.append(ClientUtils.escapeQueryChars(sessionId));
|
||||
|
||||
try {
|
||||
indexUpdateCallback.getSolrGroup()
|
||||
.deleteByQuery(buf.toString());
|
||||
} catch (final Exception e) {
|
||||
logger.error("Could not delete old docs at "
|
||||
+ dataCrawlingConfig, e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
|
@ -290,7 +317,7 @@ public class DataIndexHelper implements Serializable {
|
|||
}
|
||||
|
||||
public String getCrawlingSessionId() {
|
||||
return initParamMap.get("crawlingSessionId");
|
||||
return initParamMap.get(Constants.CRAWLING_SESSION_ID);
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
|
|
Loading…
Add table
Reference in a new issue