SOLR-6383: RegexTransformer returns no results after replaceAll if regex does not match a value

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1618488 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2014-08-17 17:51:13 +00:00
parent 7b967b74b3
commit 4f9bc97179
3 changed files with 21 additions and 3 deletions

View File

@ -282,6 +282,9 @@ Bug Fixes
* SOLR-6380: Added missing context info to log message if IOException occurs in processing tlog
(Steven Bower via hossman)
* SOLR-6383: RegexTransformer returns no results after replaceAll if regex does not match a value.
(Alexander Kingson, shalin)
Optimizations
---------------------

View File

@ -122,7 +122,7 @@ public class RegexTransformer extends Transformer {
} else if (replaceWith != null) {
Pattern p = getPattern(reStr);
Matcher m = p.matcher(value);
return m.find()? m.replaceAll(replaceWith): null;
return m.find() ? m.replaceAll(replaceWith) : value;
} else {
return readfromRegExp(reStr, value, col, groupNames);
}

View File

@ -98,6 +98,20 @@ public class TestRegexTransformer extends AbstractDataImportHandlerTestCase {
Map<String, Object> result = new RegexTransformer().transformRow(src,
context);
assertEquals("D''souza", result.get("name"));
fld = getField("title_underscore", "string", "\\s+", "title", null);
fld.put(REPLACE_WITH, "_");
fields.clear();
fields.add(fld);
context = getContext(null, null, null, Context.FULL_DUMP, fields, null);
src.clear();
src.put("title", "value with spaces"); // a value which will match the regex
result = new RegexTransformer().transformRow(src, context);
assertEquals("value_with_spaces", result.get("title_underscore"));
src.clear();
src.put("title", "valueWithoutSpaces"); // value which will not match regex
result = new RegexTransformer().transformRow(src, context);
assertEquals("valueWithoutSpaces", result.get("title_underscore")); // value should be returned as-is
}
@Test
@ -117,7 +131,7 @@ public class TestRegexTransformer extends AbstractDataImportHandlerTestCase {
fld = getField("t1", "string","duff", "rowdata", null);
fields.add(fld);
// **ATTEMPTS** a match WITH a replaceWith
// **ATTEMPTS** a match WITH a replaceWith (should return original data)
// <field column="t2" sourceColName="rowdata" regexp="duff" replaceWith="60"/>
fld = getField("t2", "string","duff", "rowdata", null);
fld.put(REPLACE_WITH, "60");
@ -140,7 +154,8 @@ public class TestRegexTransformer extends AbstractDataImportHandlerTestCase {
Context context = getContext(null, resolver, null, Context.FULL_DUMP, fields, eAttrs);
Map<String, Object> result = new RegexTransformer().transformRow(row, context);
assertEquals(5, result.size());
assertEquals(6, result.size());
assertEquals(s, result.get("t2"));
assertEquals(s, result.get("rowdata"));
assertEquals("26", result.get("highway_mileage"));
assertEquals("19", result.get("city_mileage"));