Skip to content

Commit

Permalink
fix(provider/gce): Allow short queries with explicit flag (#511)
Browse files Browse the repository at this point in the history
The search endpoint rejects short queries, returning an empty
result set.  There are a few cases where we need to pass a short
query; create an explicit flag to make this possible.
  • Loading branch information
ezimanyi committed Mar 1, 2018
1 parent edd0ad3 commit ecf61b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ class SearchController {
@RequestParam(value = "platform", required = false) String platform,
@RequestParam(value = "pageSize", defaultValue = "10000", required = false) int pageSize,
@RequestParam(value = "page", defaultValue = "1", required = false) int page,
@RequestParam(value = "allowShortQuery", defaultValue = "false", required = false) boolean allowShortQuery,
@RequestHeader(value = "X-RateLimit-App", required = false) String sourceApp,
HttpServletRequest httpServletRequest) {
if (query?.size() < 3) {
if (!allowShortQuery && query?.size() < 3) {
// keyword searches must have a minimum of 3 characters
return []
}

def filters = httpServletRequest.getParameterNames().findAll { String parameterName ->
!["q", "type", "platform", "pageSize", "page"].contains(parameterName)
!["q", "type", "platform", "pageSize", "page", "allowShortQuery"].contains(parameterName)
}.collectEntries { String parameterName ->
[parameterName, httpServletRequest.getParameter(parameterName)]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,24 @@ class SearchControllerSpec extends Specification {
def controller = new SearchController(searchService: searchService)

@Unroll
def "should return empty results when `q` parameter is < 3 characters"() {
def "should return empty results when `q` parameter is < 3 characters and rejectShortQuery is true or omitted"() {
when:
controller.search(query, null, null, 100, 0, null, httpServletRequest).isEmpty()
controller.search(query, null, null, 100, 0, allowShortQuery, null, httpServletRequest).isEmpty()

then:
expectedSearches * searchService.search(query, null, null, null, 100, 0, [:]) >> { return [] }

where:
query || expectedSearches
null || 0
"" || 0
"a" || 0
"ab" || 0
"abc" || 1
query || allowShortQuery || expectedSearches
null || false || 0
"" || false || 0
"a" || false || 0
"ab" || false || 0
"abc" || false || 1
null || true || 1
"" || true || 1
"a" || true || 1
"ab" || true || 1
"abc" || true || 1
}
}

0 comments on commit ecf61b1

Please sign in to comment.