[Search] Add spec for ElasticSearchProvider

Add spec coverage for ElasticSearchProvider.  Also remove
unneeded guards for max number of results, as the aggregator
will always provide a max number of results.
This commit is contained in:
Pete Richards
2015-10-20 16:01:42 -07:00
parent 77d81f899b
commit 9a63e99710
3 changed files with 147 additions and 17 deletions

View File

@ -31,8 +31,7 @@ define([
) {
"use strict";
var DEFAULT_MAX_RESULTS = 100,
ID_PROPERTY = '_id',
var ID_PROPERTY = '_id',
SOURCE_PROPERTY = '_source',
SCORE_PROPERTY = '_score';
@ -42,14 +41,11 @@ define([
*
* @constructor
* @param $http Angular's $http service, for working with urls.
* @param {ObjectService} objectService the service from which
* domain objects can be gotten.
* @param ROOT the constant `ELASTIC_ROOT` which allows us to
* interact with ElasticSearch.
*/
function ElasticSearchProvider($http, objectService, ROOT) {
function ElasticSearchProvider($http, ROOT) {
this.$http = $http;
this.objectService = objectService;
this.root = ROOT;
}
@ -65,10 +61,6 @@ define([
params = {},
provider = this;
if (!maxResults) {
maxResults = DEFAULT_MAX_RESULTS;
}
searchTerm = this.cleanTerm(searchTerm);
searchTerm = this.fuzzyMatchUnquotedTerms(searchTerm);
@ -102,7 +94,7 @@ define([
* @returns {string} search terms cleaned of excess whitespace.
*/
ElasticSearchProvider.prototype.cleanTerm = function (term) {
return term.trim().replace(/ +/, ' ');
return term.trim().replace(/ +/g, ' ');
};
/**
@ -121,7 +113,8 @@ define([
return query
.replace(matcher, '~ ')
.replace('"~', '"');
.replace(/$/, '~')
.replace(/"~+/, '"');
};
/**