From 6b58a8536b998fd15c58d1b21485d13969472643 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Sat, 31 Mar 2007 17:07:26 +0000 Subject: [PATCH] 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 --- .../solr/handler/CSVRequestHandler.java | 5 ++-- .../apache/solr/handler/TestCSVLoader.java | 23 +++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/solr/handler/CSVRequestHandler.java b/src/java/org/apache/solr/handler/CSVRequestHandler.java index 9f1dda05b82..f49bcea9aa7 100755 --- a/src/java/org/apache/solr/handler/CSVRequestHandler.java +++ b/src/java/org/apache/solr/handler/CSVRequestHandler.java @@ -88,6 +88,7 @@ abstract class CSVLoader { static String FIELDNAMES="fieldnames"; static String HEADER="header"; static String SKIP="skip"; + static String SKIPLINES="skipLines"; static String MAP="map"; static String TRIM="trim"; static String EMPTY="keepEmpty"; @@ -229,7 +230,7 @@ abstract class CSVLoader { Boolean hasHeader = params.getBool(HEADER); - skipLines = params.getInt(SKIP,0); + skipLines = params.getInt(SKIPLINES,0); if (fieldnames==null) { if (null == hasHeader) { @@ -345,7 +346,7 @@ abstract class CSVLoader { addDoc(line,vals); } - if (params.getBool(COMMIT,true)) { + if (params.getBool(COMMIT,false)) { handler.commit(new CommitUpdateCommand(false)); } } diff --git a/src/test/org/apache/solr/handler/TestCSVLoader.java b/src/test/org/apache/solr/handler/TestCSVLoader.java index 18573101690..01426ed6a5d 100755 --- a/src/test/org/apache/solr/handler/TestCSVLoader.java +++ b/src/test/org/apache/solr/handler/TestCSVLoader.java @@ -86,8 +86,9 @@ public class TestCSVLoader extends AbstractSolrTestCase { public void testCSVLoad() throws Exception { makeFile("id\n100\n101\n102"); loadLocal("stream.file",filename); - // csv loader currently defaults to committing - // assertU(commit()); + // check default commit of false + assertQ(req("id:[100 TO 110]"),"//*[@numFound='0']"); + assertU(commit()); assertQ(req("id:[100 TO 110]"),"//*[@numFound='3']"); } @@ -185,12 +186,28 @@ public class TestCSVLoader extends AbstractSolrTestCase { // test that header in file was skipped 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 loadLocal("stream.file",filename, "commit","true", "fieldnames","id,my_s", "header","false"); assertQ(req("id:id"),"//*[@numFound='1']"); 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 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:102"),"//arr[@name='str_s']/str[2][.='EMPTY']"); assertQ(req("id:103"),"//str[@name='str_s'][.='EMPTY']"); + + }