From b119be488a3314d95306be979a50c3943595e090 Mon Sep 17 00:00:00 2001 From: Grant Ingersoll Date: Fri, 5 Jul 2013 18:51:16 +0000 Subject: [PATCH] SOLR-5003: add rowidOffset as well git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1500097 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/handler/loader/CSVLoaderBase.java | 5 ++++- .../src/test/org/apache/solr/handler/TestCSVLoader.java | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/solr/core/src/java/org/apache/solr/handler/loader/CSVLoaderBase.java b/solr/core/src/java/org/apache/solr/handler/loader/CSVLoaderBase.java index 1146bc6d376..454baef9a56 100644 --- a/solr/core/src/java/org/apache/solr/handler/loader/CSVLoaderBase.java +++ b/solr/core/src/java/org/apache/solr/handler/loader/CSVLoaderBase.java @@ -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); diff --git a/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java b/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java index 995db74787c..b722929527c 100755 --- a/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java +++ b/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java @@ -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