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