Skip to content
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

Adapted the website search for better matching #6477

Merged
merged 1 commit into from
Dec 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion util/gh-pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ <h1>ALL the Clippy Lints</h1>
</div>

<article class="panel panel-default" id="{{lint.id}}"
ng-repeat="lint in data | filter:byLevels | filter:byGroups | filter:search | orderBy:'id' track by lint.id" on-finish-render="ngRepeatFinished">
Copy link
Member Author

@xFrednet xFrednet Dec 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the on-finish-render="ngRepeatFinished" as it was restarting the query even though nothing has changed. Changing one of the settings causes the query to be reevaluated automatically.

ng-repeat="lint in data | filter:byLevels | filter:byGroups | filter:bySearch | orderBy:'id' track by lint.id">
<header class="panel-heading" ng-click="open[lint.id] = !open[lint.id]">
<h2 class="panel-title">
<div class="panel-title-name">
Expand Down Expand Up @@ -215,6 +215,46 @@ <h4 class="list-group-item-heading">
return $scope.groups[lint.group];
};

$scope.bySearch = function (lint, index, array) {
let search_str = $scope.search;
// It can be `null` I haven't missed this value
if (search_str == null || search_str.length == 0) {
return true;
}
search_str = search_str.toLowerCase();

// Search by id
let id_search = search_str.trim().replace(/(\-| )/g, "_");
if (lint.id.includes(id_search)) {
return true;
}

// Search the description
// The use of `for`-loops instead of `foreach` enables us to return early
let search_lint = (lint, therm) => {
for (const field in lint.docs) {
// Continue if it's not a property
if (!lint.docs.hasOwnProperty(field)) {
continue;
}

// Return if not found
if (lint.docs[field].toLowerCase().includes(therm)) {
return true;
}
}
return false;
};
let therms = search_str.split(" ");
for (index = 0; index < therms.length; index++) {
if (!search_lint(lint, therms[index])) {
return false;
}
}

return true;
}

// Get data
$scope.open = {};
$scope.loading = true;
Expand Down