CSV: default commit to false, add tests for skip, skipLines

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@524452 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2007-03-31 17:07:26 +00:00
parent f519838b7f
commit 6b58a8536b
2 changed files with 24 additions and 4 deletions

View File

@ -88,6 +88,7 @@ abstract class CSVLoader {
static String FIELDNAMES="fieldnames"; static String FIELDNAMES="fieldnames";
static String HEADER="header"; static String HEADER="header";
static String SKIP="skip"; static String SKIP="skip";
static String SKIPLINES="skipLines";
static String MAP="map"; static String MAP="map";
static String TRIM="trim"; static String TRIM="trim";
static String EMPTY="keepEmpty"; static String EMPTY="keepEmpty";
@ -229,7 +230,7 @@ abstract class CSVLoader {
Boolean hasHeader = params.getBool(HEADER); Boolean hasHeader = params.getBool(HEADER);
skipLines = params.getInt(SKIP,0); skipLines = params.getInt(SKIPLINES,0);
if (fieldnames==null) { if (fieldnames==null) {
if (null == hasHeader) { if (null == hasHeader) {
@ -345,7 +346,7 @@ abstract class CSVLoader {
addDoc(line,vals); addDoc(line,vals);
} }
if (params.getBool(COMMIT,true)) { if (params.getBool(COMMIT,false)) {
handler.commit(new CommitUpdateCommand(false)); handler.commit(new CommitUpdateCommand(false));
} }
} }

View File

@ -86,8 +86,9 @@ public class TestCSVLoader extends AbstractSolrTestCase {
public void testCSVLoad() throws Exception { public void testCSVLoad() throws Exception {
makeFile("id\n100\n101\n102"); makeFile("id\n100\n101\n102");
loadLocal("stream.file",filename); loadLocal("stream.file",filename);
// csv loader currently defaults to committing // check default commit of false
// assertU(commit()); assertQ(req("id:[100 TO 110]"),"//*[@numFound='0']");
assertU(commit());
assertQ(req("id:[100 TO 110]"),"//*[@numFound='3']"); assertQ(req("id:[100 TO 110]"),"//*[@numFound='3']");
} }
@ -185,12 +186,28 @@ public class TestCSVLoader extends AbstractSolrTestCase {
// test that header in file was skipped // test that header in file was skipped
assertQ(req("id:id"),"//*[@numFound='0']"); assertQ(req("id:id"),"//*[@numFound='0']");
// test skipping a field via the "skip" parameter
loadLocal("stream.file",filename,"commit","true","keepEmpty","true","skip","str_s");
assertQ(req("id:[100 TO 110]"),"//*[@numFound='4']");
assertQ(req("id:[100 TO 110]"),"count(//str[@name='str_s'])=0");
// test skipping a field by specifying an empty name
loadLocal("stream.file",filename,"commit","true","keepEmpty","true","fieldnames","id,");
assertQ(req("id:[100 TO 110]"),"//*[@numFound='4']");
assertQ(req("id:[100 TO 110]"),"count(//str[@name='str_s'])=0");
// test loading file as if it didn't have a header // test loading file as if it didn't have a header
loadLocal("stream.file",filename, "commit","true", loadLocal("stream.file",filename, "commit","true",
"fieldnames","id,my_s", "header","false"); "fieldnames","id,my_s", "header","false");
assertQ(req("id:id"),"//*[@numFound='1']"); assertQ(req("id:id"),"//*[@numFound='1']");
assertQ(req("id:100"),"//str[@name='my_s'][.='quoted']"); assertQ(req("id:100"),"//str[@name='my_s'][.='quoted']");
// test skipLines
loadLocal("stream.file",filename, "commit","true",
"fieldnames","id,my_s", "header","false", "skipLines","1");
assertQ(req("id:id"),"//*[@numFound='1']");
assertQ(req("id:100"),"//str[@name='my_s'][.='quoted']");
// test multi-valued fields via field splitting w/ mapping of subvalues // test multi-valued fields via field splitting w/ mapping of subvalues
makeFile("id,str_s\n" makeFile("id,str_s\n"
@ -232,6 +249,8 @@ public class TestCSVLoader extends AbstractSolrTestCase {
assertQ(req("id:101"),"//arr[@name='str_s']/str[3][.='c']"); assertQ(req("id:101"),"//arr[@name='str_s']/str[3][.='c']");
assertQ(req("id:102"),"//arr[@name='str_s']/str[2][.='EMPTY']"); assertQ(req("id:102"),"//arr[@name='str_s']/str[2][.='EMPTY']");
assertQ(req("id:103"),"//str[@name='str_s'][.='EMPTY']"); assertQ(req("id:103"),"//str[@name='str_s'][.='EMPTY']");
} }