Fixed regex text search facet to handle errors better. Use .text() rather than .html() to render cell values, or & will not show up.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@184 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
72d06fe65c
commit
1f05954924
@ -1,6 +1,7 @@
|
|||||||
package com.metaweb.gridworks.browsing.facets;
|
package com.metaweb.gridworks.browsing.facets;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -18,8 +19,9 @@ public class TextSearchFacet implements Facet {
|
|||||||
protected String _columnName;
|
protected String _columnName;
|
||||||
protected int _cellIndex;
|
protected int _cellIndex;
|
||||||
protected String _query;
|
protected String _query;
|
||||||
|
protected Pattern _pattern;
|
||||||
|
|
||||||
protected String _mode;
|
protected String _mode;
|
||||||
protected boolean _caseSensitive;
|
protected boolean _caseSensitive;
|
||||||
|
|
||||||
public TextSearchFacet() {
|
public TextSearchFacet() {
|
||||||
@ -50,8 +52,18 @@ public class TextSearchFacet implements Facet {
|
|||||||
_caseSensitive = o.getBoolean("caseSensitive");
|
_caseSensitive = o.getBoolean("caseSensitive");
|
||||||
if (_query != null) {
|
if (_query != null) {
|
||||||
_query = _query.trim();
|
_query = _query.trim();
|
||||||
if (!_caseSensitive) {
|
if (_query.length() > 0) {
|
||||||
_query = _query.toLowerCase();
|
if (!_caseSensitive) {
|
||||||
|
_query = _query.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("regex".equals(_mode)) {
|
||||||
|
try {
|
||||||
|
_pattern = Pattern.compile(_query);
|
||||||
|
} catch (java.util.regex.PatternSyntaxException e) {
|
||||||
|
//e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,6 +71,8 @@ public class TextSearchFacet implements Facet {
|
|||||||
public RowFilter getRowFilter() {
|
public RowFilter getRowFilter() {
|
||||||
if (_query == null || _query.length() == 0) {
|
if (_query == null || _query.length() == 0) {
|
||||||
return null;
|
return null;
|
||||||
|
} else if ("regex".equals(_mode) && _pattern == null) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Evaluable eval = new VariableExpr("value");
|
Evaluable eval = new VariableExpr("value");
|
||||||
@ -66,7 +80,7 @@ public class TextSearchFacet implements Facet {
|
|||||||
if ("regex".equals(_mode)) {
|
if ("regex".equals(_mode)) {
|
||||||
return new ExpressionStringComparisonRowFilter(eval, _cellIndex) {
|
return new ExpressionStringComparisonRowFilter(eval, _cellIndex) {
|
||||||
protected boolean checkValue(String s) {
|
protected boolean checkValue(String s) {
|
||||||
return s.matches(_query);
|
return _pattern.matcher(s).find();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
@ -20,11 +20,11 @@ DataTableCellUI.prototype._render = function() {
|
|||||||
} else if ("e" in cell) {
|
} else if ("e" in cell) {
|
||||||
$('<span>').addClass("data-table-error").text(cell.e).appendTo(divContent);
|
$('<span>').addClass("data-table-error").text(cell.e).appendTo(divContent);
|
||||||
} else if (!("r" in cell) || cell.r == null) {
|
} else if (!("r" in cell) || cell.r == null) {
|
||||||
$(divContent).html(cell.v);
|
$(divContent).text(cell.v);
|
||||||
} else {
|
} else {
|
||||||
var r = cell.r;
|
var r = cell.r;
|
||||||
if (r.j == "new") {
|
if (r.j == "new") {
|
||||||
$(divContent).html(cell.v + " (new topic)");
|
$(divContent).text(cell.v + " (new topic)");
|
||||||
|
|
||||||
$('<span> </span>').appendTo(divContent);
|
$('<span> </span>').appendTo(divContent);
|
||||||
$('<a href="javascript:{}">re-match</a>')
|
$('<a href="javascript:{}">re-match</a>')
|
||||||
@ -47,7 +47,7 @@ DataTableCellUI.prototype._render = function() {
|
|||||||
self._doRematch();
|
self._doRematch();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$(divContent).html(cell.v);
|
$(divContent).text(cell.v);
|
||||||
|
|
||||||
if (this._dataTableView._showRecon) {
|
if (this._dataTableView._showRecon) {
|
||||||
var ul = $('<div></div>').addClass("data-table-recon-candidates").appendTo(divContent);
|
var ul = $('<div></div>').addClass("data-table-recon-candidates").appendTo(divContent);
|
||||||
|
Loading…
Reference in New Issue
Block a user