From 8eda495aa7551c7e47731244659f8934231c8b24 Mon Sep 17 00:00:00 2001 From: shale Date: Fri, 10 Jul 2015 15:06:19 -0700 Subject: [PATCH] [Search] Results without folders Folders are now no longer included in the results list. --- .../features/search/src/SearchController.js | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/platform/features/search/src/SearchController.js b/platform/features/search/src/SearchController.js index bcd278ac6e..9dce798660 100644 --- a/platform/features/search/src/SearchController.js +++ b/platform/features/search/src/SearchController.js @@ -82,30 +82,35 @@ define(function () { }); } - // Search through items for items which contain the search term - // in the title + // Search through items for items which contain the search term in the name function search(term) { console.log('search called, with term ', term); var searchResults = [], itemsLength, + itemModel, itemName, i; + // Make not case sensitive if (term) { term = term.toLocaleLowerCase(); } - // refresh items list + // Refresh items list return listify().then( function () { - itemsLength = $scope.items.length; // Slight time optimization + // Slight time optimization + itemsLength = $scope.items.length; + for (i = 0; i < itemsLength; i += 1) { - itemName = $scope.items[i].getModel().name; - console.log('items[', i, '] name', itemName); - if (itemName.toLocaleLowerCase().includes(term)) { + itemModel = $scope.items[i].getModel(); + itemName = itemModel.name.toLocaleLowerCase(); + + // Include any matching items, except folders + if (itemName.includes(term) && itemModel.type !== 'folder') { searchResults.push($scope.items[i]); } } - console.log('search results ', searchResults); + $scope.results = searchResults; // Somewhat redundant return searchResults; });