mirror of
https://github.com/nasa/openmct.git
synced 2025-03-24 04:55:21 +00:00
[Search] Dump before revert
Commtting changes so far before revering to a previous commit. Most changes to make next() have been unneccsiary. We no longer want next().
This commit is contained in:
parent
5520037908
commit
1891b24bde
@ -42,7 +42,7 @@
|
||||
"provides": "searchService",
|
||||
"type": "provider",
|
||||
"implementation": "providers/GenericSearchProvider.js",
|
||||
"depends": [ "objectService" ]
|
||||
"depends": [ "$rootScope", "objectService", "workerService" ]
|
||||
},
|
||||
{
|
||||
"provides": "searchService",
|
||||
@ -55,6 +55,13 @@
|
||||
"type": "aggregator",
|
||||
"implementation": "SearchAggregator.js"
|
||||
}
|
||||
],
|
||||
"workers": [
|
||||
{
|
||||
"key": "genericSearchWorker",
|
||||
"scriptUrl": "workers/GenericSearchWorker.js",
|
||||
"depends": [ "objectService" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -29,7 +29,7 @@
|
||||
<input type="text"
|
||||
id="searchinput"
|
||||
value=""
|
||||
ng-keypress="controller.search('searchinput')"
|
||||
ng-keyup="controller.search('searchinput')"
|
||||
style="width: 66%"/>
|
||||
</div>
|
||||
|
||||
|
@ -54,21 +54,64 @@ define(
|
||||
|
||||
// Remove extra objects that have the same ID
|
||||
function filterRepeats(results) {
|
||||
var ids = [];
|
||||
var ids = [],
|
||||
idToIndicies = {}, // 'dictionary' mapping IDs to a list of indicies
|
||||
filteredResults = [];
|
||||
|
||||
// Create a list of indicies of objects that correspond to any object ID
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
var id = results[i].id;
|
||||
|
||||
if (idToIndicies[id]) {
|
||||
// If the ID already exists in the dictionary, push this index to
|
||||
// the end of the array it points to
|
||||
idToIndicies[id].push(i);
|
||||
} else {
|
||||
// Else make a new entry in the dictionary with this ID, pointing
|
||||
// to this index
|
||||
idToIndicies[id] = [i];
|
||||
// And also add this ID to the list of IDs that we have seen
|
||||
ids.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
// Now for each ID in the dictionary, we want to use the version of
|
||||
// the object that has a higher score
|
||||
for (var i = 0; i < ids.length; i++) {
|
||||
var id = ids[i],
|
||||
indicies = idToIndicies[id],
|
||||
highestScoringObject;
|
||||
|
||||
highestScoringObject = results[ indicies[0] ];
|
||||
for (var j = 0; j < indicies.length; j++) {
|
||||
// If the score of the object corresponding to this index of the results
|
||||
// list has a higher score than the one we have, choose it instead
|
||||
if (results[indicies[j]].score > highestScoringObject.score) {
|
||||
highestScoringObject = results[indicies[j]];
|
||||
}
|
||||
}
|
||||
filteredResults.push(highestScoringObject);
|
||||
}
|
||||
|
||||
/*
|
||||
for (var i = 0; i < results.length; i += 1) {
|
||||
if (ids.indexOf(results[i].id) !== -1) {
|
||||
if (results[i] === undefined) {
|
||||
// Catch any leftover undefined objects
|
||||
results.splice(i, 1);
|
||||
i--;
|
||||
} else if (ids.indexOf(results[i].id) !== -1) {
|
||||
// If this result's ID is already there, remove the object
|
||||
results.splice(i, 1);
|
||||
// Reduce loop index because we shortened the array
|
||||
i -= 1;
|
||||
i--;
|
||||
} else {
|
||||
// Otherwise add the ID to the list of the ones we have seen
|
||||
ids.push(results[i].id);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return results;
|
||||
return filteredResults;
|
||||
}
|
||||
|
||||
// Order the objects from highest to lowest score in the array
|
||||
@ -84,9 +127,11 @@ define(
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
console.log('score', results[i].score, 'for', results[i].object.getModel().name);
|
||||
}
|
||||
*/
|
||||
|
||||
return results;
|
||||
}
|
||||
|
@ -144,6 +144,8 @@ define(
|
||||
scores[ ids[i] ] = results[i][SCORE];
|
||||
}
|
||||
|
||||
//console.log('scores {}', scores);
|
||||
|
||||
// Get the domain objects from their IDs
|
||||
return objectService.getObjects(ids).then(function (objects) {
|
||||
|
||||
@ -166,7 +168,13 @@ define(
|
||||
}
|
||||
}
|
||||
|
||||
console.log('setting latest search results with', searchResults);
|
||||
/*
|
||||
for (var k = 0; k < searchResults.length; k++) {
|
||||
console.log('ES score', searchResults[k].score, 'for', searchResults[k].object.getModel().name);
|
||||
}
|
||||
*/
|
||||
|
||||
//console.log('setting latest search results with', searchResults);
|
||||
latestSearchResults = searchResults;
|
||||
return searchResults;
|
||||
});
|
||||
|
@ -226,7 +226,7 @@ define(
|
||||
// Prevent errors from getModel not being defined
|
||||
if (latestItems[i].object.getModel) {
|
||||
latestItems[i].score = score(latestItems[i], curentSearchTerms, currentSeachInput);
|
||||
|
||||
//console.log('item', latestItems[i].object.getModel().name, 'score', latestItems[i].score);
|
||||
// Include any items that match the terms and are of valid type
|
||||
if (latestItems[i].score > 0 && validType(latestItems[i].object.getModel())) {
|
||||
// Add the result to the result list
|
||||
@ -310,7 +310,7 @@ define(
|
||||
|
||||
// Get the first search result
|
||||
var firstResult = first(input);
|
||||
console.log('generic return', firstResult);
|
||||
//console.log('generic return', firstResult);
|
||||
|
||||
return firstResult;
|
||||
});
|
||||
|
74
platform/features/search/src/workers/GenericSearchWorker.js
Normal file
74
platform/features/search/src/workers/GenericSearchWorker.js
Normal file
@ -0,0 +1,74 @@
|
||||
/*****************************************************************************
|
||||
* 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";
|
||||
|
||||
// Recursive helper function for getItems()
|
||||
function itemsHelper(children, i) {
|
||||
if (i >= children.length) {
|
||||
// Done!
|
||||
return children;
|
||||
} else if (children[i].hasCapability('composition')) {
|
||||
// This child has children
|
||||
return children[i].getCapability('composition').invoke().then(function (grandchildren) {
|
||||
// Add grandchildren to the end of the list
|
||||
// They will also be checked for composition
|
||||
return itemsHelper(children.concat(grandchildren), i + 1);
|
||||
});
|
||||
} else {
|
||||
// This child is a leaf
|
||||
return itemsHelper(children, i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Converts the filetree into a list
|
||||
function getItems(objectService) {
|
||||
// Aquire My Items (root folder)
|
||||
return objectService.getObjects(['mine']).then(function (objects) {
|
||||
// Get all of its descendents
|
||||
return itemsHelper([objects.mine], 0).then(function (items) {
|
||||
// Turn them into searchResult objects (object, id, and score)
|
||||
var searchResultItems = [];
|
||||
|
||||
for (var i = 0; i < items.length; i += 1) {
|
||||
searchResultItems.push({
|
||||
id: items[i].getId(),
|
||||
object: items[i],
|
||||
score: 0 // Assign actual score when filtering for term
|
||||
});
|
||||
}
|
||||
|
||||
//console.log('searchResultItems (in Everything)', searchResultItems);
|
||||
return searchResultItems;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
self.onmessage = function (event) {
|
||||
//console.log('in worker .. 1');
|
||||
//console.log('event.data', event.data);
|
||||
//console.log('objects 0', objects[0]);
|
||||
self.postMessage(itemsHelper(event.data, 0));
|
||||
};
|
||||
}());
|
Loading…
x
Reference in New Issue
Block a user