mirror of https://github.com/apache/lucene.git
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:
parent
7b967b74b3
commit
4f9bc97179
|
@ -282,6 +282,9 @@ Bug Fixes
|
||||||
* SOLR-6380: Added missing context info to log message if IOException occurs in processing tlog
|
* SOLR-6380: Added missing context info to log message if IOException occurs in processing tlog
|
||||||
(Steven Bower via hossman)
|
(Steven Bower via hossman)
|
||||||
|
|
||||||
|
* SOLR-6383: RegexTransformer returns no results after replaceAll if regex does not match a value.
|
||||||
|
(Alexander Kingson, shalin)
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,7 @@ public class RegexTransformer extends Transformer {
|
||||||
} else if (replaceWith != null) {
|
} else if (replaceWith != null) {
|
||||||
Pattern p = getPattern(reStr);
|
Pattern p = getPattern(reStr);
|
||||||
Matcher m = p.matcher(value);
|
Matcher m = p.matcher(value);
|
||||||
return m.find()? m.replaceAll(replaceWith): null;
|
return m.find() ? m.replaceAll(replaceWith) : value;
|
||||||
} else {
|
} else {
|
||||||
return readfromRegExp(reStr, value, col, groupNames);
|
return readfromRegExp(reStr, value, col, groupNames);
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,20 @@ public class TestRegexTransformer extends AbstractDataImportHandlerTestCase {
|
||||||
Map<String, Object> result = new RegexTransformer().transformRow(src,
|
Map<String, Object> result = new RegexTransformer().transformRow(src,
|
||||||
context);
|
context);
|
||||||
assertEquals("D''souza", result.get("name"));
|
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
|
@Test
|
||||||
|
@ -117,7 +131,7 @@ public class TestRegexTransformer extends AbstractDataImportHandlerTestCase {
|
||||||
fld = getField("t1", "string","duff", "rowdata", null);
|
fld = getField("t1", "string","duff", "rowdata", null);
|
||||||
fields.add(fld);
|
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"/>
|
// <field column="t2" sourceColName="rowdata" regexp="duff" replaceWith="60"/>
|
||||||
fld = getField("t2", "string","duff", "rowdata", null);
|
fld = getField("t2", "string","duff", "rowdata", null);
|
||||||
fld.put(REPLACE_WITH, "60");
|
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);
|
Context context = getContext(null, resolver, null, Context.FULL_DUMP, fields, eAttrs);
|
||||||
|
|
||||||
Map<String, Object> result = new RegexTransformer().transformRow(row, context);
|
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(s, result.get("rowdata"));
|
||||||
assertEquals("26", result.get("highway_mileage"));
|
assertEquals("26", result.get("highway_mileage"));
|
||||||
assertEquals("19", result.get("city_mileage"));
|
assertEquals("19", result.get("city_mileage"));
|
||||||
|
|
Loading…
Reference in New Issue