mirror of
https://github.com/zulip/zulip.git
synced 2025-10-31 20:13:46 +00:00
We probably should have done this a while ago, even though these functions are pretty tiny. The goal here is to make it easier to have more consistent search semantics. Our first use case is subs.js. In this case we are able to decouple a bit of generic string matching from the subs-specific code.
38 lines
895 B
JavaScript
38 lines
895 B
JavaScript
var search_util = (function () {
|
|
|
|
var exports = {};
|
|
|
|
exports.get_search_terms = function (input) {
|
|
var search_terms = input.toLowerCase().split(",").map(function (s) {
|
|
return s.trim();
|
|
});
|
|
return search_terms;
|
|
};
|
|
|
|
exports.vanilla_match = function (opts) {
|
|
/*
|
|
This is a pretty vanilla search criteria
|
|
where we see if any of our search terms
|
|
is in our value. When in doubt we should use
|
|
this for all Zulip filters, but we may
|
|
have more complicated use cases in some
|
|
places.
|
|
|
|
This is case insensitive.
|
|
*/
|
|
var val = opts.val.toLowerCase();
|
|
return _.any(opts.search_terms, function (term) {
|
|
if (val.indexOf(term) !== -1) {
|
|
return true;
|
|
}
|
|
});
|
|
};
|
|
|
|
return exports;
|
|
|
|
}());
|
|
if (typeof module !== 'undefined') {
|
|
module.exports = search_util;
|
|
}
|
|
window.search_util = search_util;
|