@@ 118,6 118,17 @@ namespace Oliver {
}
}
+ /**
+ * Filter items by query
+ *
+ * A query is a list of words, separate by space
+ * Each word cam be:
+ * - a text, which is case-insensitively searched inside 'file' and 'message'
+ * - a number, which exactly match a line number
+ * - an exclamation point (!), which match only results marked as "important"
+ *
+ * Each words in query must match to return the item
+ */
public class ResultFilter : Gtk.Filter {
private string _query = "";
public string query {
@@ 150,8 161,23 @@ namespace Oliver {
}
var obj = (ResultData) item;
- debug ("ResultFilter.match '%s' , '%s'", obj.file, this.query);
- return obj.file.casefold (). contains (this.query.casefold ());
+
+ string[] ascii_alternates;
+ string[] tokens = this.query.tokenize_and_fold ("en", out ascii_alternates);
+ debug ("match query tokens ['%s']", string.joinv ("', '", tokens));
+
+ int score = 0;
+ foreach(string token in tokens) {
+ var match = obj.file.casefold ().contains (token);
+ match = match || obj.message.casefold ().contains (token);
+ match = match || obj.line.to_string () == token;
+ if (token == "!") {
+ match = match && obj.important;
+ }
+ if (match) score++;
+ }
+
+ return score == tokens.length;
}
}
}