-
Notifications
You must be signed in to change notification settings - Fork 898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improving speed of List.search #679
Comments
You can also use this faster search without needing to modify the List.js library: just pass it as a custom search argument: see #678 listObj.search('Jonny', searchFunction); // Custom search for Jonny
listObj.search('Jonny', ['name'], searchFunction); // Custom search in the 'name' column
function searchFunction(searchString, columns) {
for (var k = 0, kl = listObj.items.length; k < kl; k++) {
var item = listObj.items[k];
item.found = false;
if (searchString === "") continue;
var values = item.values();
for (var j = 0, jl = columns.length; j < jl; j++) {
var column = columns[j];
if (values.hasOwnProperty(column) && values[column] !== undefined && values[column] !== null) {
var text = (typeof values[column] !== 'string') ? values[column].toString() : values[column];
if (text.toLowerCase().indexOf(searchString) !== -1) {
item.found = true;
break;
}
}
}
}; |
Now updated to move item.values() call out of inner loop, thanks to @buczek |
This is awesome and now a part of #696 ❤️ |
It'll be release as part of |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For large numbers of items and/or slower CPUs the speed of searching can become noticeable. This drop-in replacement optimises the standard search function in list.js/src/search.js:
with:
Search is 63% faster in Chrome v80 and 30% faster in Firefox v74. The 2 biggest wins are replacing
text.search(searchString)
(for regular expressions, but List.js only supports searching on a string) withtext.indexOf(searchString)
, and only calling.toString()
in the inner loop if needed.Here is a JSPerf comparing 3 different case-insensitive string matching functions.
The text was updated successfully, but these errors were encountered: