mirror of
https://github.com/nasa/openmct.git
synced 2025-02-22 02:06:49 +00:00
[Serach] Webworker indexes items
The indexItem() part of the web worker seems to be working at this point.
This commit is contained in:
parent
c1dcd8ea5b
commit
7adcfc221a
@ -85,7 +85,8 @@ define(
|
|||||||
function indexItem(domainObject) {
|
function indexItem(domainObject) {
|
||||||
var message = {
|
var message = {
|
||||||
request: 'index',
|
request: 'index',
|
||||||
model: domainObject.getModel()
|
model: domainObject.getModel(),
|
||||||
|
id: domainObject.getId()
|
||||||
};
|
};
|
||||||
// Note that getModel() by definition returns a JavaScript object
|
// Note that getModel() by definition returns a JavaScript object
|
||||||
// that can be losslesly converted to a JSON object.
|
// that can be losslesly converted to a JSON object.
|
||||||
@ -106,7 +107,7 @@ define(
|
|||||||
|
|
||||||
function handleResponse(event) {
|
function handleResponse(event) {
|
||||||
//latest = event.data;
|
//latest = event.data;
|
||||||
//console.log('handleResponse', event.data);
|
console.log('handleResponse', event.data);
|
||||||
//$rootScope.$apply();
|
//$rootScope.$apply();
|
||||||
//requestNext();
|
//requestNext();
|
||||||
}
|
}
|
||||||
@ -152,6 +153,9 @@ define(
|
|||||||
var searchResultItems = [];
|
var searchResultItems = [];
|
||||||
|
|
||||||
for (var i = 0; i < items.length; i += 1) {
|
for (var i = 0; i < items.length; i += 1) {
|
||||||
|
// Test out calling worker indexItem
|
||||||
|
indexItem(items[i]);
|
||||||
|
|
||||||
searchResultItems.push({
|
searchResultItems.push({
|
||||||
id: items[i].getId(),
|
id: items[i].getId(),
|
||||||
object: items[i],
|
object: items[i],
|
||||||
@ -165,8 +169,6 @@ define(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Process the search input. Makes an array of search terms
|
// Process the search input. Makes an array of search terms
|
||||||
// by splitting up the input at spaces.
|
// by splitting up the input at spaces.
|
||||||
function process(input) {
|
function process(input) {
|
||||||
@ -279,6 +281,9 @@ define(
|
|||||||
} else {
|
} else {
|
||||||
resultsLength = maxResults;
|
resultsLength = maxResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test out calling the web worker search
|
||||||
|
workerSearch(input, maxResults);
|
||||||
|
|
||||||
// Then filter through the items list
|
// Then filter through the items list
|
||||||
searchResults = filterResults(searchResultItems, input, resultsLength);
|
searchResults = filterResults(searchResultItems, input, resultsLength);
|
||||||
|
@ -24,20 +24,41 @@
|
|||||||
(function () {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
// An array of objects composed of domain object IDs and models
|
||||||
|
// {id: domainObject's ID, model: domainObject's model}
|
||||||
var indexedItems = [];
|
var indexedItems = [];
|
||||||
|
|
||||||
|
function conainsItem(id) {
|
||||||
|
for (var i = 0; i < indexedItems.length; i++) {
|
||||||
|
if (indexedItems[i].id === id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function index(data) {
|
function index(data) {
|
||||||
// Takes an object model
|
// Takes an object model
|
||||||
// Add to indexedItems
|
// Add to indexedItems
|
||||||
|
console.log('webworker index', data);
|
||||||
|
if (!conainsItem(data.id)) {
|
||||||
|
indexedItems.push({
|
||||||
|
id: data.id,
|
||||||
|
model: data.model
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function search(data) {
|
function search(data) {
|
||||||
// Takes a search input and the number of items to find
|
// Takes a search input and the number of items to find
|
||||||
// Converts it into search terms
|
// Converts it into search terms
|
||||||
// Gets matches from indexedItems
|
// Gets matches from indexedItems
|
||||||
|
console.log('webworker search', data);
|
||||||
|
console.log('webworker indexedItems', indexedItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.onmessage = function (event) {
|
self.onmessage = function (event) {
|
||||||
|
console.log('webworker onmessage');
|
||||||
if (event.data.request === 'index') {
|
if (event.data.request === 'index') {
|
||||||
self.postMessage(index(event.data));
|
self.postMessage(index(event.data));
|
||||||
} else if (event.data.request === 'search') {
|
} else if (event.data.request === 'search') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user