mirror of
https://github.com/nasa/openmct.git
synced 2025-05-30 14:14:19 +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') {
|
if (event.data.request === 'search') {
|
||||||
// Convert the ids given from the web worker into domain objects
|
// Convert the ids given from the web worker into domain objects
|
||||||
var ids = [];
|
var ids = [];
|
||||||
for (var i = 0; i < event.data.results.length; i++) {
|
for (var id in event.data.results) {
|
||||||
ids.push(event.data.results[i].id);
|
ids.push(id);
|
||||||
}
|
}
|
||||||
objectService.getObjects(ids).then(function (objects) {
|
objectService.getObjects(ids).then(function (objects) {
|
||||||
latestResults = [];
|
latestResults = [];
|
||||||
for (var id in objects) {
|
for (var id in objects) {
|
||||||
latestResults.push({
|
latestResults.push({
|
||||||
object: objects[id],
|
object: objects[id],
|
||||||
id: id
|
id: id,
|
||||||
// TODO: Make the event.data.results able to get score from id
|
score: event.data.results[id].score
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
lastSearchTimestamp = event.data.timestamp;
|
lastSearchTimestamp = event.data.timestamp;
|
||||||
@ -152,10 +152,12 @@ define(
|
|||||||
* in the case where other search services are not avaliable.
|
* in the case where other search services are not avaliable.
|
||||||
* Notes:
|
* Notes:
|
||||||
* * The order of the results is not guarenteed.
|
* * The order of the results is not guarenteed.
|
||||||
* * A domain object qualifies as a match for a search term if
|
* * A domain object qualifies as a match for a search input if
|
||||||
* the object's name property contains the exact search term
|
* the object's name property contains any of the search terms
|
||||||
* as a substring.
|
* (which are generated by splitting the input at spaces).
|
||||||
* * Wildcards are not supported.
|
* * 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
|
* @param inputID the name of the ID property of the html text
|
||||||
* input where this funcion should find the search term
|
* input where this funcion should find the search term
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*global self*/
|
/*global self*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module defining GenericSearchWorker. Created by shale on 07/21/2015.
|
||||||
|
*/
|
||||||
(function () {
|
(function () {
|
||||||
"use strict";
|
"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) {
|
function index(data) {
|
||||||
// Takes an object model
|
|
||||||
// Add to indexedItems
|
|
||||||
|
|
||||||
// TODO: Since this is only within genericsearch, do
|
// TODO: Since this is only within genericsearch, do
|
||||||
// we really need to check if the index already holds it?
|
// we really need to check if the index already holds it?
|
||||||
// This might depend on how often/when we clear indexedItems.
|
// 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) {
|
function search(data) {
|
||||||
// Takes a search input and the number of items to find
|
// This results 'dictionary' will have domain object ID keys which
|
||||||
// Converts it into search terms
|
// point to the domain object's score. (The score is wrt only this
|
||||||
// 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
|
|
||||||
// specific search input.)
|
// specific search input.)
|
||||||
// TODO: It may be unnecissary for results to have models in it.
|
var results = {},
|
||||||
var results = [],
|
|
||||||
input = data.input.toLocaleLowerCase(),
|
input = data.input.toLocaleLowerCase(),
|
||||||
terms = convertToTerms(input),
|
terms = convertToTerms(input),
|
||||||
timesToLoop = Math.min(indexedItems.length, data.maxNumber);
|
timesToLoop = Math.min(indexedItems.length, data.maxNumber);
|
||||||
@ -126,11 +132,10 @@
|
|||||||
for (var i = 0; i < timesToLoop; i++) {
|
for (var i = 0; i < timesToLoop; i++) {
|
||||||
var score = scoreItem(indexedItems[i], input, terms);
|
var score = scoreItem(indexedItems[i], input, terms);
|
||||||
if (score > 0) {
|
if (score > 0) {
|
||||||
results.push({
|
results[indexedItems[i].id] = {
|
||||||
id: indexedItems[i].id,
|
|
||||||
model: indexedItems[i].model,
|
|
||||||
score: score
|
score: score
|
||||||
});
|
};
|
||||||
|
console.log(results[indexedItems[i].id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user