Search on device for words

pull/209/head
M66B 2 years ago
parent 8c20cf7969
commit 0991ad8d69

@ -854,7 +854,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
if (word.size() == 0) if (word.size() == 0)
return true; return true;
Pattern pat = Pattern.compile(".*" + TextUtils.join("\\s+", word) + ".*", Pattern.DOTALL); Pattern pat = Pattern.compile(".*?\\b(" + TextUtils.join("\\s+", word) + ")\\b.*?", Pattern.DOTALL);
return pat.matcher(text).matches(); return pat.matcher(text).matches();
} }

@ -2949,9 +2949,9 @@ public class HtmlHelper {
int flags = Pattern.DOTALL | Pattern.CASE_INSENSITIVE; int flags = Pattern.DOTALL | Pattern.CASE_INSENSITIVE;
List<Pattern> pat = new ArrayList<>(); List<Pattern> pat = new ArrayList<>();
pat.add(Pattern.compile(".*(" + TextUtils.join("\\s+", word) + ").*", flags)); pat.add(Pattern.compile(".*?\\b(" + TextUtils.join("\\s+", word) + ")\\b.*?", flags));
for (String w : plus) for (String w : plus)
pat.add(Pattern.compile(".*(" + w + ").*", flags)); pat.add(Pattern.compile(".*?\\b(" + w + ")\\b.*?", flags));
for (Pattern p : pat) for (Pattern p : pat)
NodeTraversor.traverse(new NodeVisitor() { NodeTraversor.traverse(new NodeVisitor() {
@ -2963,25 +2963,26 @@ public class HtmlHelper {
String text = tnode.getWholeText(); String text = tnode.getWholeText();
Matcher result = p.matcher(text); Matcher result = p.matcher(text);
if (!result.matches())
return;
int prev = 0; int prev = 0;
Element holder = document.createElement("span"); Element holder = document.createElement("span");
for (int i = 1; i <= result.groupCount(); i++) { while (result.find()) {
holder.appendText(text.substring(prev, result.start(i))); holder.appendText(text.substring(prev, result.start(1)));
Element span = document.createElement("span"); Element span = document.createElement("span");
span.attr("style", mergeStyles( span.attr("style", mergeStyles(
span.attr("style"), span.attr("style"),
"font-size:larger; background-color:" + encodeWebColor(color) "font-size:larger; background-color:" + encodeWebColor(color)
)); ));
span.text(text.substring(result.start(i), result.end(i))); span.text(text.substring(result.start(1), result.end(1)));
holder.appendChild(span); holder.appendChild(span);
prev = result.end(i); prev = result.end(1);
} }
if (prev == 0) // No matches
return;
if (prev < text.length()) if (prev < text.length())
holder.appendText(text.substring(prev)); holder.appendText(text.substring(prev));

Loading…
Cancel
Save