Commit 7e6e5ea3 authored by Mahdi Mahmoudy's avatar Mahdi Mahmoudy
Browse files

final tested fix for brakets in the search term

parent 774052fa
...@@ -319,9 +319,20 @@ wsService.factory('searchService', [ ...@@ -319,9 +319,20 @@ wsService.factory('searchService', [
'$http', '$http',
'ENV', 'ENV',
function ($http, ENV) { function ($http, ENV) {
// to escape special characters which aren't supported
// by the API end-point
function escapeSearchTerm(searchTerm) {
if (!searchTerm) {
return searchTerm;
}
return searchTerm
.replace(/\[(.*)\]/, "%5B$1%5D"); // [ and ]
};
return { return {
findTerms: function (searchTerm, limit, page, facet, filters) { findTerms: function (searchTerm, limit, page, facet, filters) {
var url = ENV.apiEndpoint + '/internal/search/ontology?query=' + searchTerm + '&limit=' + limit + '&page=' + (page var url = ENV.apiEndpoint + '/internal/search/ontology?query=' + escapeSearchTerm(searchTerm) + '&limit=' + limit + '&page=' + (page
? page ? page
: 1) + '&facet=' + (facet : 1) + '&facet=' + (facet
? facet ? facet
...@@ -331,7 +342,7 @@ wsService.factory('searchService', [ ...@@ -331,7 +342,7 @@ wsService.factory('searchService', [
return $http.get(url); return $http.get(url);
}, },
findGeneProducts: function (searchTerm, limit, page, facet, filters) { findGeneProducts: function (searchTerm, limit, page, facet, filters) {
var url = ENV.apiEndpoint + '/geneproduct/search?query=' + searchTerm + '&limit=' + limit + '&page=' + (page var url = ENV.apiEndpoint + '/geneproduct/search?query=' + escapeSearchTerm(searchTerm) + '&limit=' + limit + '&page=' + (page
? page ? page
: 1) + '&facet=' + (facet : 1) + '&facet=' + (facet
? facet ? facet
...@@ -351,13 +362,13 @@ wsService.factory('searchService', [ ...@@ -351,13 +362,13 @@ wsService.factory('searchService', [
return $http.get(url); return $http.get(url);
}, },
getAnnotationsForTermUrl: function (searchTerm) { getAnnotationsForTermUrl: function (searchTerm) {
return 'goUsage=descendants&goUsageRelationships=is_a,part_of,occurs_in&goId=' + searchTerm; return 'goUsage=descendants&goUsageRelationships=is_a,part_of,occurs_in&goId=' + escapeSearchTerm(searchTerm);
}, },
getAnnotationsForECOUrl: function (searchTerm) { getAnnotationsForECOUrl: function (searchTerm) {
return 'evidenceCodeUsage=descendants&evidenceCode=' + searchTerm; return 'evidenceCodeUsage=descendants&evidenceCode=' + escapeSearchTerm(searchTerm);
}, },
getAnnotationsForProductUrl: function (searchTerm) { getAnnotationsForProductUrl: function (searchTerm) {
return 'geneProductId=' + searchTerm; return 'geneProductId=' + escapeSearchTerm(searchTerm);
}, },
findAnnotationsForFilterUrl: function (url) { findAnnotationsForFilterUrl: function (url) {
return $http.get(ENV.apiEndpoint + '/annotation/search?' + url); return $http.get(ENV.apiEndpoint + '/annotation/search?' + url);
...@@ -370,7 +381,8 @@ wsService.factory('searchService', [ ...@@ -370,7 +381,8 @@ wsService.factory('searchService', [
} }
}); });
return queryString; return queryString;
} },
escapeSearchTerm: escapeSearchTerm,
}; };
} }
]); ]);
......
...@@ -107,7 +107,10 @@ app.controller('FacetSearchCtrl', function($scope, $location, searchService, $ro ...@@ -107,7 +107,10 @@ app.controller('FacetSearchCtrl', function($scope, $location, searchService, $ro
if (!text) { if (!text) {
return text; return text;
} }
return text.replace(new RegExp($scope.searchTerm, 'gi'), '<em>' + $scope.searchTerm + '</em>'); return text.replace(
new RegExp(searchService.escapeSearchTerm($scope.searchTerm), 'gi'),
'<em>' + $scope.searchTerm + '</em>'
);
}; };
getResultsPage(type); getResultsPage(type);
......
'use strict'; 'use strict';
app.controller('SearchCtrl', function($scope, $location, $routeParams) { app.controller('SearchCtrl', function($scope, $location, $routeParams, searchService) {
$scope.searchTerm = $routeParams.searchTerm $scope.searchTerm = $routeParams.searchTerm;
.replace(/\[(.*)\]/, "%5B$1%5D");
}); });
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment