Commit 8be62785 authored by Quxl's avatar Quxl

x

parent a1a520a0
package com.egolm.search.common;
import java.util.ArrayList;
import java.util.List;
import com.egolm.search.config.XException;
public class ListUtil {
public static <T> List<List<T>> split(List<T> list, int length) {
if(length <= 0) {
throw new XException("List split error, length must greater then 0");
}
List<List<T>> result = new ArrayList<List<T>>();
if(list != null && list.size() > 0) {
int size = list.size();
int count = (size + length - 1) / length;
for (int i = 0; i < count; i++) {
List<T> subList = list.subList(i * length, ((i + 1) * length > size ? size : length * (i + 1)));
result.add(subList);
}
}
return result;
}
}
......@@ -8,8 +8,8 @@ import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.common.SolrInputDocument;
import com.egolm.common.StringUtil;
import com.egolm.search.common.ListUtil;
import com.egolm.search.config.XRException;
import com.google.common.collect.Lists;
public abstract class AbstractSolrApi implements SolrApi {
......@@ -29,7 +29,7 @@ public abstract class AbstractSolrApi implements SolrApi {
docs.add(solrInputDocument);
}
List<List<SolrInputDocument>> doclist = Lists.partition(docs, 1000);
List<List<SolrInputDocument>> doclist = ListUtil.split(docs, 1000);
for(List<SolrInputDocument> tmp : doclist) {
solrClient.add(tmp);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment