diff --git a/platform/features/search/src/providers/GenericSearchProvider.js b/platform/features/search/src/providers/GenericSearchProvider.js index 5e5c2738f1..1e02f55397 100644 --- a/platform/features/search/src/providers/GenericSearchProvider.js +++ b/platform/features/search/src/providers/GenericSearchProvider.js @@ -46,10 +46,10 @@ define( function GenericSearchProvider($rootScope, objectService, workerService) { var validType = function () {return true;}; - /* var worker = workerService.run('genericSearchWorker'), lastestItems; + /* function requestItems() { // Aquire My Items (root folder) // I don't think we can do this part in the webworker because of the objectService @@ -81,9 +81,33 @@ define( } */ + // Tell the web worker to add a new item's model to its list of items. + function indexItem(domainObject) { + var message = { + request: 'index', + model: domainObject.getModel() + }; + // Note that getModel() by definition returns a JavaScript object + // that can be losslesly converted to a JSON object. + worker.postMessage(message); + } + + // Tell the worker to search for items it has that match this searchInput. + // Takes the searchInput, as well as a max number of results (will return + // less than that if there are fewer matches). + function workerSearch(searchInput, numberOfResults) { + var message = { + request: 'search', + input: searchInput, + number: numberOfResults + }; + worker.postMessage(message); + } + function handleResponse(event) { - latest = event.data; - $rootScope.$apply(); + //latest = event.data; + //console.log('handleResponse', event.data); + //$rootScope.$apply(); //requestNext(); } diff --git a/platform/features/search/src/workers/GenericSearchWorker.js b/platform/features/search/src/workers/GenericSearchWorker.js new file mode 100644 index 0000000000..e8bb0c1d4c --- /dev/null +++ b/platform/features/search/src/workers/GenericSearchWorker.js @@ -0,0 +1,47 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +/*global self*/ + +(function () { + "use strict"; + + var indexedItems = []; + + function index(data) { + // Takes an object model + // Add to indexedItems + } + + function search(data) { + // Takes a search input and the number of items to find + // Converts it into search terms + // Gets matches from indexedItems + } + + self.onmessage = function (event) { + if (event.data.request === 'index') { + self.postMessage(index(event.data)); + } else if (event.data.request === 'search') { + self.postMessage(search(event.data)); + } + }; +}()); \ No newline at end of file