mirror of
https://github.com/nasa/openmct.git
synced 2025-04-01 16:41:02 +00:00
[Search] Changed worker result implementation
The interface remains the same, but the web worker returns a pseudo dictionary (actually an object) after being told the search. The key value pairs for this dictionary are ids and scores.
This commit is contained in:
parent
5a93e5a2bc
commit
7934e8d425
@ -79,16 +79,16 @@ define(
|
||||
if (event.data.request === 'search') {
|
||||
// Convert the ids given from the web worker into domain objects
|
||||
var ids = [];
|
||||
for (var i = 0; i < event.data.results.length; i++) {
|
||||
ids.push(event.data.results[i].id);
|
||||
for (var id in event.data.results) {
|
||||
ids.push(id);
|
||||
}
|
||||
objectService.getObjects(ids).then(function (objects) {
|
||||
latestResults = [];
|
||||
for (var id in objects) {
|
||||
latestResults.push({
|
||||
object: objects[id],
|
||||
id: id
|
||||
// TODO: Make the event.data.results able to get score from id
|
||||
id: id,
|
||||
score: event.data.results[id].score
|
||||
});
|
||||
}
|
||||
lastSearchTimestamp = event.data.timestamp;
|
||||
@ -152,10 +152,12 @@ define(
|
||||
* in the case where other search services are not avaliable.
|
||||
* Notes:
|
||||
* * The order of the results is not guarenteed.
|
||||
* * A domain object qualifies as a match for a search term if
|
||||
* the object's name property contains the exact search term
|
||||
* as a substring.
|
||||
* * Wildcards are not supported.
|
||||
* * A domain object qualifies as a match for a search input if
|
||||
* the object's name property contains any of the search terms
|
||||
* (which are generated by splitting the input at spaces).
|
||||
* * Scores are higher for matches that have more than one of
|
||||
* the terms as substrings.
|
||||
* * Wildcards are not (yet?) supported.
|
||||
*
|
||||
* @param inputID the name of the ID property of the html text
|
||||
* input where this funcion should find the search term
|
||||
|
@ -21,6 +21,9 @@
|
||||
*****************************************************************************/
|
||||
/*global self*/
|
||||
|
||||
/**
|
||||
* Module defining GenericSearchWorker. Created by shale on 07/21/2015.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
@ -39,12 +42,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Indexes an item to indexedItems.
|
||||
*
|
||||
* @param data An object which contains:
|
||||
* * model: The model of the domain object
|
||||
* * id: The ID of the domain object
|
||||
*/
|
||||
function index(data) {
|
||||
// Takes an object model
|
||||
// Add to indexedItems
|
||||
|
||||
// TODO: Since this is only within genericsearch, do
|
||||
// we really need to check if the index already holds it?
|
||||
// This might depend on how often/when we clear indexedItems.
|
||||
@ -107,18 +111,20 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets search results from the indexedItems based on provided search
|
||||
* input. Returns matching results from indexedItems, as well as the
|
||||
* timestamp that was passed to it.
|
||||
*
|
||||
* @param data An object which contains:
|
||||
* * input: The original string which we are searching with
|
||||
* * maxNumber: The maximum number of search results desired
|
||||
* * timestamp: The time identifier from when the query was made
|
||||
*/
|
||||
function search(data) {
|
||||
// Takes a search input and the number of items to find
|
||||
// Converts it into search terms
|
||||
// Gets matches from indexedItems
|
||||
|
||||
// This results array will hold objects which are composed of
|
||||
// the object's id, model, and score. (The score is wrt only this
|
||||
// This results 'dictionary' will have domain object ID keys which
|
||||
// point to the domain object's score. (The score is wrt only this
|
||||
// specific search input.)
|
||||
// TODO: It may be unnecissary for results to have models in it.
|
||||
var results = [],
|
||||
var results = {},
|
||||
input = data.input.toLocaleLowerCase(),
|
||||
terms = convertToTerms(input),
|
||||
timesToLoop = Math.min(indexedItems.length, data.maxNumber);
|
||||
@ -126,11 +132,10 @@
|
||||
for (var i = 0; i < timesToLoop; i++) {
|
||||
var score = scoreItem(indexedItems[i], input, terms);
|
||||
if (score > 0) {
|
||||
results.push({
|
||||
id: indexedItems[i].id,
|
||||
model: indexedItems[i].model,
|
||||
results[indexedItems[i].id] = {
|
||||
score: score
|
||||
});
|
||||
};
|
||||
console.log(results[indexedItems[i].id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user