diff --git a/platform/search/bundle.js b/platform/search/bundle.js index c26d5ce8ab..01d3d01eb4 100644 --- a/platform/search/bundle.js +++ b/platform/search/bundle.js @@ -100,7 +100,8 @@ define([ "modelService", "workerService", "topic", - "GENERIC_SEARCH_ROOTS" + "GENERIC_SEARCH_ROOTS", + "openmct" ] }, { diff --git a/platform/search/src/services/GenericSearchProvider.js b/platform/search/src/services/GenericSearchProvider.js index 6a9b430e47..8d9913b634 100644 --- a/platform/search/src/services/GenericSearchProvider.js +++ b/platform/search/src/services/GenericSearchProvider.js @@ -25,9 +25,11 @@ * Module defining GenericSearchProvider. Created by shale on 07/16/2015. */ define([ - + '../../../../src/api/objects/object-utils', + 'lodash' ], function ( - + objectUtils, + _ ) { /** @@ -42,11 +44,12 @@ define([ * @param {TopicService} topic the topic service. * @param {Array} ROOTS An array of object Ids to begin indexing. */ - function GenericSearchProvider($q, $log, modelService, workerService, topic, ROOTS) { + function GenericSearchProvider($q, $log, modelService, workerService, topic, ROOTS, openmct) { var provider = this; this.$q = $q; this.$log = $log; this.modelService = modelService; + this.openmct = openmct; this.indexedIds = {}; this.idsToIndex = []; @@ -171,17 +174,29 @@ define([ GenericSearchProvider.prototype.index = function (id, model) { var provider = this; - this.worker.postMessage({ - request: 'index', - model: model, - id: id - }); - - if (Array.isArray(model.composition)) { - model.composition.forEach(function (idToIndex) { - provider.scheduleForIndexing(idToIndex); + if (id !== 'ROOT') { + this.worker.postMessage({ + request: 'index', + model: model, + id: id }); } + + var domainObject = objectUtils.toNewFormat(model, id); + var composition = _.find(this.openmct.composition.registry, function (p) { + return p.appliesTo(domainObject); + }); + + if (!composition) { + return; + } + + composition.load(domainObject) + .then(function (children) { + children.forEach(function (child) { + provider.scheduleForIndexing(objectUtils.makeKeyString(child)); + }); + }); }; /** diff --git a/platform/search/test/services/GenericSearchProviderSpec.js b/platform/search/test/services/GenericSearchProviderSpec.js index fb306eecdf..30ddab83fc 100644 --- a/platform/search/test/services/GenericSearchProviderSpec.js +++ b/platform/search/test/services/GenericSearchProviderSpec.js @@ -39,6 +39,8 @@ define([ topic, mutationTopic, ROOTS, + compositionProvider, + openmct, provider; beforeEach(function () { @@ -77,6 +79,21 @@ define([ ROOTS = [ 'mine' ]; + compositionProvider = jasmine.createSpyObj( + 'compositionProvider', + ['load', 'appliesTo'] + ); + compositionProvider.load.andCallFake(function (domainObject) { + return Promise.resolve(domainObject.composition); + }); + compositionProvider.appliesTo.andCallFake(function (domainObject) { + return !!domainObject.composition; + }); + openmct = { + composition: { + registry: [compositionProvider] + } + }; spyOn(GenericSearchProvider.prototype, 'scheduleForIndexing'); @@ -86,7 +103,8 @@ define([ modelService, workerService, topic, - ROOTS + ROOTS, + openmct ); }); @@ -208,13 +226,42 @@ define([ it('schedules composed ids for indexing', function () { var id = 'anId', - model = {composition: ['abc', 'def']}; + model = {composition: ['abc', 'def']}, + calls = provider.scheduleForIndexing.calls.length; provider.index(id, model); - expect(provider.scheduleForIndexing) - .toHaveBeenCalledWith('abc'); - expect(provider.scheduleForIndexing) - .toHaveBeenCalledWith('def'); + + expect(compositionProvider.appliesTo).toHaveBeenCalledWith({ + identifier: {key: 'anId', namespace: ''}, + composition: [jasmine.any(Object), jasmine.any(Object)] + }); + + expect(compositionProvider.load).toHaveBeenCalledWith({ + identifier: {key: 'anId', namespace: ''}, + composition: [jasmine.any(Object), jasmine.any(Object)] + }); + + waitsFor(function () { + return provider.scheduleForIndexing.calls.length > calls; + }); + + runs(function () { + expect(provider.scheduleForIndexing) + .toHaveBeenCalledWith('abc'); + expect(provider.scheduleForIndexing) + .toHaveBeenCalledWith('def'); + }); + }); + + it('does not index ROOT, but checks composition', function () { + var id = 'ROOT', + model = {}; + + provider.index(id, model); + expect(worker.postMessage).not.toHaveBeenCalled(); + expect(compositionProvider.appliesTo).toHaveBeenCalledWith({ + identifier: {key: 'ROOT', namespace: ''} + }); }); });