2015-08-03 17:21:50 +00:00
|
|
|
/*****************************************************************************
|
2018-05-14 22:46:17 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2018, United States Government
|
2015-08-03 17:21:50 +00:00
|
|
|
* as represented by the Administrator of the National Aeronautics and Space
|
|
|
|
* Administration. All rights reserved.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
2015-10-20 20:55:46 +00:00
|
|
|
* 'License'); you may not use this file except in compliance with the License.
|
2015-08-03 17:21:50 +00:00
|
|
|
* 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
|
2015-10-20 20:55:46 +00:00
|
|
|
* distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
|
2015-08-03 17:21:50 +00:00
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT includes source code licensed under additional open source
|
2015-08-03 17:21:50 +00:00
|
|
|
* 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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-04-08 23:22:28 +00:00
|
|
|
/*global require*/
|
2016-03-04 20:30:23 +00:00
|
|
|
|
2015-08-03 17:21:50 +00:00
|
|
|
/**
|
|
|
|
* SearchSpec. Created by shale on 07/31/2015.
|
|
|
|
*/
|
2015-10-20 20:55:46 +00:00
|
|
|
define([
|
2015-10-17 00:33:23 +00:00
|
|
|
|
2015-10-20 20:55:46 +00:00
|
|
|
], function (
|
2015-10-17 00:33:23 +00:00
|
|
|
|
2015-10-20 20:55:46 +00:00
|
|
|
) {
|
2015-10-17 00:33:23 +00:00
|
|
|
|
2015-10-20 20:55:46 +00:00
|
|
|
describe('GenericSearchWorker', function () {
|
|
|
|
// If this test fails, make sure this path is correct
|
|
|
|
var worker,
|
|
|
|
objectX,
|
|
|
|
objectY,
|
|
|
|
objectZ,
|
2018-06-30 00:32:59 +00:00
|
|
|
itemsToIndex;
|
2015-10-17 00:33:23 +00:00
|
|
|
|
2015-10-20 20:55:46 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
worker = new Worker(
|
|
|
|
require.toUrl('platform/search/src/services/GenericSearchWorker.js')
|
|
|
|
);
|
|
|
|
|
|
|
|
objectX = {
|
|
|
|
id: 'x',
|
|
|
|
model: {name: 'object xx'}
|
|
|
|
};
|
|
|
|
objectY = {
|
|
|
|
id: 'y',
|
|
|
|
model: {name: 'object yy'}
|
|
|
|
};
|
|
|
|
objectZ = {
|
|
|
|
id: 'z',
|
|
|
|
model: {name: 'object zz'}
|
|
|
|
};
|
|
|
|
itemsToIndex = [
|
|
|
|
objectX,
|
|
|
|
objectY,
|
|
|
|
objectZ
|
|
|
|
];
|
2015-10-17 00:33:23 +00:00
|
|
|
|
2015-10-20 20:55:46 +00:00
|
|
|
itemsToIndex.forEach(function (item) {
|
|
|
|
worker.postMessage({
|
|
|
|
request: 'index',
|
|
|
|
id: item.id,
|
|
|
|
model: item.model
|
2015-08-03 17:21:50 +00:00
|
|
|
});
|
|
|
|
});
|
2015-10-20 20:55:46 +00:00
|
|
|
});
|
2015-10-17 00:33:23 +00:00
|
|
|
|
2015-10-20 20:55:46 +00:00
|
|
|
afterEach(function () {
|
|
|
|
worker.terminate();
|
|
|
|
});
|
2015-10-17 00:33:23 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
it('returns search results for partial term matches', function (done) {
|
|
|
|
worker.addEventListener('message', function (message) {
|
|
|
|
var data = message.data;
|
2015-10-20 20:55:46 +00:00
|
|
|
expect(data.request).toBe('search');
|
|
|
|
expect(data.total).toBe(3);
|
|
|
|
expect(data.queryId).toBe(123);
|
|
|
|
expect(data.results.length).toBe(3);
|
|
|
|
expect(data.results[0].item.id).toBe('x');
|
|
|
|
expect(data.results[0].item.model).toEqual(objectX.model);
|
|
|
|
expect(data.results[0].matchCount).toBe(1);
|
|
|
|
expect(data.results[1].item.id).toBe('y');
|
|
|
|
expect(data.results[1].item.model).toEqual(objectY.model);
|
|
|
|
expect(data.results[1].matchCount).toBe(1);
|
|
|
|
expect(data.results[2].item.id).toBe('z');
|
|
|
|
expect(data.results[2].item.model).toEqual(objectZ.model);
|
|
|
|
expect(data.results[2].matchCount).toBe(1);
|
2018-06-30 00:32:59 +00:00
|
|
|
|
|
|
|
done();
|
2015-10-20 20:55:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
worker.postMessage({
|
|
|
|
request: 'search',
|
2018-06-30 00:32:59 +00:00
|
|
|
input: 'obj',
|
2015-10-20 20:55:46 +00:00
|
|
|
maxResults: 100,
|
2018-06-30 00:32:59 +00:00
|
|
|
queryId: 123
|
2015-10-20 20:55:46 +00:00
|
|
|
});
|
2018-06-30 00:32:59 +00:00
|
|
|
});
|
2015-10-20 20:55:46 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
it('scores exact term matches higher', function (done) {
|
|
|
|
worker.addEventListener('message', function (message) {
|
|
|
|
expect(message.data.queryId).toBe(234);
|
|
|
|
expect(message.data.results.length).toBe(3);
|
|
|
|
expect(message.data.results[0].item.id).toBe('x');
|
|
|
|
expect(message.data.results[0].matchCount).toBe(1.5);
|
2015-10-20 20:55:46 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
done();
|
2015-10-20 20:55:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
worker.postMessage({
|
|
|
|
request: 'search',
|
2018-06-30 00:32:59 +00:00
|
|
|
input: 'object',
|
2015-10-20 20:55:46 +00:00
|
|
|
maxResults: 100,
|
2018-06-30 00:32:59 +00:00
|
|
|
queryId: 234
|
2015-10-20 20:55:46 +00:00
|
|
|
});
|
2018-06-30 00:32:59 +00:00
|
|
|
});
|
2015-10-20 20:55:46 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
it('can find partial term matches', function (done) {
|
|
|
|
worker.addEventListener('message', function (message) {
|
|
|
|
expect(message.data.queryId).toBe(345);
|
|
|
|
expect(message.data.results.length).toBe(1);
|
|
|
|
expect(message.data.results[0].item.id).toBe('x');
|
|
|
|
expect(message.data.results[0].matchCount).toBe(1);
|
2015-10-20 20:55:46 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
done();
|
2015-10-20 20:55:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
worker.postMessage({
|
|
|
|
request: 'search',
|
2018-06-30 00:32:59 +00:00
|
|
|
input: 'x',
|
2015-10-20 20:55:46 +00:00
|
|
|
maxResults: 100,
|
2018-06-30 00:32:59 +00:00
|
|
|
queryId: 345
|
2015-10-20 20:55:46 +00:00
|
|
|
});
|
2018-06-30 00:32:59 +00:00
|
|
|
});
|
2015-10-20 20:55:46 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
it('matches individual terms', function (done) {
|
|
|
|
worker.addEventListener('message', function (message) {
|
|
|
|
var data = message.data;
|
2015-10-20 20:55:46 +00:00
|
|
|
|
|
|
|
expect(data.queryId).toBe(456);
|
|
|
|
expect(data.results.length).toBe(3);
|
|
|
|
expect(data.results[0].item.id).toBe('x');
|
|
|
|
expect(data.results[0].matchCount).toBe(1);
|
|
|
|
expect(data.results[1].item.id).toBe('y');
|
|
|
|
expect(data.results[1].matchCount).toBe(1);
|
|
|
|
expect(data.results[2].item.id).toBe('z');
|
|
|
|
expect(data.results[1].matchCount).toBe(1);
|
2018-06-30 00:32:59 +00:00
|
|
|
|
|
|
|
done();
|
2015-10-20 20:55:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
worker.postMessage({
|
|
|
|
request: 'search',
|
2018-06-30 00:32:59 +00:00
|
|
|
input: 'x y z',
|
2015-10-20 20:55:46 +00:00
|
|
|
maxResults: 100,
|
2018-06-30 00:32:59 +00:00
|
|
|
queryId: 456
|
2015-10-20 20:55:46 +00:00
|
|
|
});
|
2018-06-30 00:32:59 +00:00
|
|
|
});
|
2015-10-20 20:55:46 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
it('scores exact matches highest', function (done) {
|
|
|
|
worker.addEventListener('message', function (message) {
|
|
|
|
var data = message.data;
|
2015-10-20 20:55:46 +00:00
|
|
|
|
|
|
|
expect(data.queryId).toBe(567);
|
|
|
|
expect(data.results.length).toBe(3);
|
|
|
|
expect(data.results[0].item.id).toBe('x');
|
|
|
|
expect(data.results[0].matchCount).toBe(103);
|
|
|
|
expect(data.results[1].matchCount).toBe(1.5);
|
|
|
|
expect(data.results[2].matchCount).toBe(1.5);
|
2018-06-30 00:32:59 +00:00
|
|
|
|
|
|
|
done();
|
2015-10-20 20:55:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
worker.postMessage({
|
|
|
|
request: 'search',
|
2018-06-30 00:32:59 +00:00
|
|
|
input: 'object xx',
|
2015-10-20 20:55:46 +00:00
|
|
|
maxResults: 100,
|
2018-06-30 00:32:59 +00:00
|
|
|
queryId: 567
|
2015-10-20 20:55:46 +00:00
|
|
|
});
|
2018-06-30 00:32:59 +00:00
|
|
|
});
|
2015-10-20 20:55:46 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
it('scores multiple term match above single match', function () {
|
|
|
|
worker.addEventListener('message', function (message) {
|
|
|
|
var data = message.data;
|
2015-10-20 20:55:46 +00:00
|
|
|
|
|
|
|
expect(data.queryId).toBe(678);
|
|
|
|
expect(data.results.length).toBe(3);
|
|
|
|
expect(data.results[0].item.id).toBe('x');
|
|
|
|
expect(data.results[0].matchCount).toBe(2);
|
|
|
|
expect(data.results[1].matchCount).toBe(1);
|
|
|
|
expect(data.results[2].matchCount).toBe(1);
|
2015-08-03 17:21:50 +00:00
|
|
|
});
|
2018-06-30 00:32:59 +00:00
|
|
|
|
|
|
|
worker.postMessage({
|
|
|
|
request: 'search',
|
|
|
|
input: 'obj x',
|
|
|
|
maxResults: 100,
|
|
|
|
queryId: 678
|
|
|
|
});
|
2015-08-03 17:21:50 +00:00
|
|
|
});
|
2015-10-20 20:55:46 +00:00
|
|
|
});
|
|
|
|
});
|