SOLR-5003: add rowidOffset as well

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1500097 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2013-07-05 18:51:16 +00:00
parent 218856ac6d
commit b119be488a
2 changed files with 12 additions and 1 deletions

View File

@ -56,6 +56,7 @@ abstract class CSVLoaderBase extends ContentStreamLoader {
public static final String OVERWRITE="overwrite";
public static final String LITERALS_PREFIX = "literal.";
public static final String ROW_ID = "rowid";
public static final String ROW_ID_OFFSET = "rowidOffset";
private static Pattern colonSplit = Pattern.compile(":");
private static Pattern commaSplit = Pattern.compile(",");
@ -74,6 +75,7 @@ abstract class CSVLoaderBase extends ContentStreamLoader {
CSVLoaderBase.FieldAdder[] adders;
String rowId = null;// if not null, add a special field by the name given with the line number/row id as the value
int rowIdOffset = 0; //add to line/rowid before creating the field
int skipLines; // number of lines to skip at start of file
@ -190,6 +192,7 @@ abstract class CSVLoaderBase extends ContentStreamLoader {
if (escape.length()!=1) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Invalid escape:'"+escape+"'");
}
rowId = params.get(ROW_ID);
rowIdOffset = params.getInt(ROW_ID_OFFSET, 0);
// if only encapsulator or escape is set, disable the other escaping mechanism
if (encapsulator == null && escape != null) {
@ -398,7 +401,7 @@ abstract class CSVLoaderBase extends ContentStreamLoader {
doc.addField(fn, val);
}
if (rowId != null){
doc.addField(rowId, line);
doc.addField(rowId, line + rowIdOffset);
}
template.solrDoc = doc;
processor.processAdd(template);

View File

@ -116,6 +116,14 @@ public class TestCSVLoader extends SolrTestCaseJ4 {
assertQ(req("rowid_i:1"),"//*[@numFound='1']");
assertQ(req("rowid_i:2"),"//*[@numFound='1']");
assertQ(req("rowid_i:100"),"//*[@numFound='0']");
makeFile("id\n200\n201\n202");
loadLocal("rowid", "rowid_i", "rowidOffset", "100");//add a special field
// check default commit of false
assertU(commit());
assertQ(req("rowid_i:101"),"//*[@numFound='1']");
assertQ(req("rowid_i:102"),"//*[@numFound='1']");
assertQ(req("rowid_i:10000"),"//*[@numFound='0']");
}
@Test