[Serach] Webworker indexes items

The indexItem() part of the web worker seems
to be working at this point.
This commit is contained in:
shale 2015-07-21 10:10:34 -07:00
parent c1dcd8ea5b
commit 7adcfc221a
2 changed files with 30 additions and 4 deletions

View File

@ -85,7 +85,8 @@ define(
function indexItem(domainObject) {
var message = {
request: 'index',
model: domainObject.getModel()
model: domainObject.getModel(),
id: domainObject.getId()
};
// Note that getModel() by definition returns a JavaScript object
// that can be losslesly converted to a JSON object.
@ -106,7 +107,7 @@ define(
function handleResponse(event) {
//latest = event.data;
//console.log('handleResponse', event.data);
console.log('handleResponse', event.data);
//$rootScope.$apply();
//requestNext();
}
@ -152,6 +153,9 @@ define(
var searchResultItems = [];
for (var i = 0; i < items.length; i += 1) {
// Test out calling worker indexItem
indexItem(items[i]);
searchResultItems.push({
id: items[i].getId(),
object: items[i],
@ -165,8 +169,6 @@ define(
});
}
// Process the search input. Makes an array of search terms
// by splitting up the input at spaces.
function process(input) {
@ -279,6 +281,9 @@ define(
} else {
resultsLength = maxResults;
}
// Test out calling the web worker search
workerSearch(input, maxResults);
// Then filter through the items list
searchResults = filterResults(searchResultItems, input, resultsLength);

View File

@ -24,20 +24,41 @@
(function () {
"use strict";
// An array of objects composed of domain object IDs and models
// {id: domainObject's ID, model: domainObject's model}
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) {
// Takes an object model
// Add to indexedItems
console.log('webworker index', data);
if (!conainsItem(data.id)) {
indexedItems.push({
id: data.id,
model: data.model
});
}
}
function search(data) {
// Takes a search input and the number of items to find
// Converts it into search terms
// Gets matches from indexedItems
console.log('webworker search', data);
console.log('webworker indexedItems', indexedItems);
}
self.onmessage = function (event) {
console.log('webworker onmessage');
if (event.data.request === 'index') {
self.postMessage(index(event.data));
} else if (event.data.request === 'search') {