~fabrixxm/oliver

b81f92a24586697665ce1d37bf2d4ca2938fa327 — fabrixxm 5 months ago ad20210
Enhanced search

- search in file name and message
- search file number
- filter important items
- multiple words
1 files changed, 28 insertions(+), 2 deletions(-)

M src/result.vala
M src/result.vala => src/result.vala +28 -2
@@ 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;
        }
    }
}