diff --git a/platform/search/src/services/GenericSearchProvider.js b/platform/search/src/services/GenericSearchProvider.js index 3d8ac39251..5c1b724c2b 100644 --- a/platform/search/src/services/GenericSearchProvider.js +++ b/platform/search/src/services/GenericSearchProvider.js @@ -48,6 +48,7 @@ define( */ function GenericSearchProvider($q, objectService, workerService, ROOTS) { var worker = workerService.run('genericSearchWorker'), + indexed = {}, pendingQueries = {}; // pendingQueries is a dictionary with the key value pairs st // the key is the timestamp and the value is the promise @@ -122,21 +123,25 @@ define( // Helper function for getItems(). Indexes the tree. function indexItems(nodes) { - console.log('nodes', nodes); nodes.forEach(function (node) { - // Index each item with the web worker - indexItem(node); + var id = node.getId(); - if (node.hasCapability('composition')) { - // This node has children - node.getCapability('composition').invoke().then(function (children) { - // Index the children - if (children.constructor === Array) { - indexItems(children); - } else { - indexItems([children]); - } - }); + if (!indexed[id]) { + // Index each item with the web worker + indexItem(node); + indexed[id] = true; + + if (node.hasCapability('composition')) { + // This node has children + node.getCapability('composition').invoke().then(function (children) { + // Index the children + if (children.constructor === Array) { + indexItems(children); + } else { + indexItems([children]); + } + }); + } } }); }