|
|
@ -2960,78 +2960,79 @@ public class HtmlHelper {
|
|
|
|
return ssb;
|
|
|
|
return ssb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Document highlightSearched(Context context, Document document, String query) {
|
|
|
|
static void highlightSearched(Context context, Document document, String query) {
|
|
|
|
int color = Helper.resolveColor(context, R.attr.colorHighlight);
|
|
|
|
try {
|
|
|
|
query = Normalizer.normalize(query, Normalizer.Form.NFKD)
|
|
|
|
int color = Helper.resolveColor(context, R.attr.colorHighlight);
|
|
|
|
.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
|
|
|
|
query = Fts4DbHelper.preprocessText(query);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: fix highlighting pre processed text
|
|
|
|
// TODO breakText
|
|
|
|
|
|
|
|
// TODO: fix highlighting pre processed text
|
|
|
|
List<String> word = new ArrayList<>();
|
|
|
|
|
|
|
|
List<String> plus = new ArrayList<>();
|
|
|
|
List<String> word = new ArrayList<>();
|
|
|
|
for (String w : query.trim().split("\\s+"))
|
|
|
|
List<String> plus = new ArrayList<>();
|
|
|
|
if (w.length() > 1 && (w.startsWith("+") || w.startsWith("-"))) {
|
|
|
|
for (String w : query.trim().split("\\s+"))
|
|
|
|
if (w.startsWith("+"))
|
|
|
|
if (w.length() > 1 && (w.startsWith("+") || w.startsWith("-"))) {
|
|
|
|
plus.add(w.substring(1));
|
|
|
|
if (w.startsWith("+"))
|
|
|
|
} else
|
|
|
|
plus.add(Pattern.quote(w.substring(1)));
|
|
|
|
word.add(w);
|
|
|
|
} else
|
|
|
|
|
|
|
|
word.add(Pattern.quote(w));
|
|
|
|
int flags = Pattern.DOTALL | Pattern.CASE_INSENSITIVE;
|
|
|
|
|
|
|
|
List<Pattern> pat = new ArrayList<>();
|
|
|
|
|
|
|
|
pat.add(Pattern.compile(".*?\\b(" + TextUtils.join("\\s+", word) + ")\\b.*?", flags));
|
|
|
|
|
|
|
|
for (String w : plus)
|
|
|
|
|
|
|
|
pat.add(Pattern.compile(".*?\\b(" + w + ")\\b.*?", flags));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Pattern p : pat)
|
|
|
|
|
|
|
|
NodeTraversor.traverse(new NodeVisitor() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void head(Node node, int depth) {
|
|
|
|
|
|
|
|
if (node instanceof TextNode)
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
TextNode tnode = (TextNode) node;
|
|
|
|
|
|
|
|
String text = Normalizer.normalize(tnode.getWholeText(), Normalizer.Form.NFKD)
|
|
|
|
|
|
|
|
.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Matcher result = p.matcher(text);
|
|
|
|
int flags = Pattern.DOTALL | Pattern.CASE_INSENSITIVE;
|
|
|
|
|
|
|
|
List<Pattern> pat = new ArrayList<>();
|
|
|
|
|
|
|
|
pat.add(Pattern.compile(".*?\\b(" + TextUtils.join("\\s+", word) + ")\\b.*?", flags));
|
|
|
|
|
|
|
|
for (String w : plus)
|
|
|
|
|
|
|
|
pat.add(Pattern.compile(".*?\\b(" + w + ")\\b.*?", flags));
|
|
|
|
|
|
|
|
|
|
|
|
int prev = 0;
|
|
|
|
for (Pattern p : pat)
|
|
|
|
Element holder = document.createElement("span");
|
|
|
|
NodeTraversor.traverse(new NodeVisitor() {
|
|
|
|
while (result.find()) {
|
|
|
|
@Override
|
|
|
|
int start = result.start(1);
|
|
|
|
public void head(Node node, int depth) {
|
|
|
|
int end = result.end(1);
|
|
|
|
if (node instanceof TextNode)
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
TextNode tnode = (TextNode) node;
|
|
|
|
|
|
|
|
String text = Fts4DbHelper.preprocessText(tnode.getWholeText());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Matcher result = p.matcher(text);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int prev = 0;
|
|
|
|
|
|
|
|
Element holder = document.createElement("span");
|
|
|
|
|
|
|
|
while (result.find()) {
|
|
|
|
|
|
|
|
int start = result.start(1);
|
|
|
|
|
|
|
|
int end = result.end(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
holder.appendText(text.substring(prev, start));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Element span = document.createElement("span");
|
|
|
|
|
|
|
|
span.attr("style", mergeStyles(
|
|
|
|
|
|
|
|
span.attr("style"),
|
|
|
|
|
|
|
|
"font-size:larger; background-color:" + encodeWebColor(color)
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
span.text(text.substring(start, end));
|
|
|
|
|
|
|
|
holder.appendChild(span);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prev = end;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
holder.appendText(text.substring(prev, start));
|
|
|
|
if (prev == 0) // No matches
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
Element span = document.createElement("span");
|
|
|
|
if (prev < text.length())
|
|
|
|
span.attr("style", mergeStyles(
|
|
|
|
holder.appendText(text.substring(prev));
|
|
|
|
span.attr("style"),
|
|
|
|
|
|
|
|
"font-size:larger; background-color:" + encodeWebColor(color)
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
span.text(text.substring(start, end));
|
|
|
|
|
|
|
|
holder.appendChild(span);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prev = end;
|
|
|
|
tnode.before(holder);
|
|
|
|
|
|
|
|
tnode.text("");
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.e(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (prev == 0) // No matches
|
|
|
|
@Override
|
|
|
|
return;
|
|
|
|
public void tail(Node node, int depth) {
|
|
|
|
|
|
|
|
}
|
|
|
|
if (prev < text.length())
|
|
|
|
}, document);
|
|
|
|
holder.appendText(text.substring(prev));
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.e(ex);
|
|
|
|
tnode.before(holder);
|
|
|
|
}
|
|
|
|
tnode.text("");
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.e(ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void tail(Node node, int depth) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, document);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return document;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Document markText(Document document) {
|
|
|
|
static Document markText(Document document) {
|
|
|
|