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:
David Huynh 2010-03-04 01:47:58 +00:00
parent 72d06fe65c
commit 1f05954924
2 changed files with 21 additions and 7 deletions

View File

@ -1,6 +1,7 @@
package com.metaweb.gridworks.browsing.facets;
import java.util.Properties;
import java.util.regex.Pattern;
import org.json.JSONException;
import org.json.JSONObject;
@ -18,8 +19,9 @@ public class TextSearchFacet implements Facet {
protected String _columnName;
protected int _cellIndex;
protected String _query;
protected Pattern _pattern;
protected String _mode;
protected String _mode;
protected boolean _caseSensitive;
public TextSearchFacet() {
@ -50,8 +52,18 @@ public class TextSearchFacet implements Facet {
_caseSensitive = o.getBoolean("caseSensitive");
if (_query != null) {
_query = _query.trim();
if (!_caseSensitive) {
_query = _query.toLowerCase();
if (_query.length() > 0) {
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() {
if (_query == null || _query.length() == 0) {
return null;
} else if ("regex".equals(_mode) && _pattern == null) {
return null;
}
Evaluable eval = new VariableExpr("value");
@ -66,7 +80,7 @@ public class TextSearchFacet implements Facet {
if ("regex".equals(_mode)) {
return new ExpressionStringComparisonRowFilter(eval, _cellIndex) {
protected boolean checkValue(String s) {
return s.matches(_query);
return _pattern.matcher(s).find();
};
};
} else {

View File

@ -20,11 +20,11 @@ DataTableCellUI.prototype._render = function() {
} else if ("e" in cell) {
$('<span>').addClass("data-table-error").text(cell.e).appendTo(divContent);
} else if (!("r" in cell) || cell.r == null) {
$(divContent).html(cell.v);
$(divContent).text(cell.v);
} else {
var r = cell.r;
if (r.j == "new") {
$(divContent).html(cell.v + " (new topic)");
$(divContent).text(cell.v + " (new topic)");
$('<span> </span>').appendTo(divContent);
$('<a href="javascript:{}">re-match</a>')
@ -47,7 +47,7 @@ DataTableCellUI.prototype._render = function() {
self._doRematch();
});
} else {
$(divContent).html(cell.v);
$(divContent).text(cell.v);
if (this._dataTableView._showRecon) {
var ul = $('<div></div>').addClass("data-table-recon-candidates").appendTo(divContent);