|
|
@ -2963,27 +2963,22 @@ public class HtmlHelper {
|
|
|
|
static void highlightSearched(Context context, Document document, String query) {
|
|
|
|
static void highlightSearched(Context context, Document document, String query) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
int color = Helper.resolveColor(context, R.attr.colorHighlight);
|
|
|
|
int color = Helper.resolveColor(context, R.attr.colorHighlight);
|
|
|
|
query = Fts4DbHelper.preprocessText(query);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO breakText
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
// TODO: fix highlighting pre processed text
|
|
|
|
for (String word : query.trim().split("\\s+")) {
|
|
|
|
|
|
|
|
if (word.startsWith("+") || word.startsWith("-"))
|
|
|
|
List<String> word = new ArrayList<>();
|
|
|
|
continue;
|
|
|
|
List<String> plus = new ArrayList<>();
|
|
|
|
for (String w : Fts4DbHelper.breakText(word).split("\\s+")) {
|
|
|
|
for (String w : query.trim().split("\\s+"))
|
|
|
|
if (sb.length() > 0)
|
|
|
|
if (w.length() > 1 && (w.startsWith("+") || w.startsWith("-"))) {
|
|
|
|
sb.append("\\s*");
|
|
|
|
if (w.startsWith("+"))
|
|
|
|
sb.append(Pattern.quote(w));
|
|
|
|
plus.add(Pattern.quote(w.substring(1)));
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
}
|
|
|
|
word.add(Pattern.quote(w));
|
|
|
|
sb.insert(0, ".*?\\b(");
|
|
|
|
|
|
|
|
sb.append(")\\b.*?");
|
|
|
|
|
|
|
|
|
|
|
|
int flags = Pattern.DOTALL | Pattern.CASE_INSENSITIVE;
|
|
|
|
Pattern p = Pattern.compile(sb.toString(), Pattern.DOTALL);
|
|
|
|
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() {
|
|
|
|
NodeTraversor.traverse(new NodeVisitor() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void head(Node node, int depth) {
|
|
|
|
public void head(Node node, int depth) {
|
|
|
|