Parses required search values from the query string @param query The HTTP query to work with @param type The type of search query requested @return A parsed SearchQuery object
(final HttpQuery query,
final SearchType type)
| 104 | * @return A parsed SearchQuery object |
| 105 | */ |
| 106 | private final SearchQuery parseQueryString(final HttpQuery query, |
| 107 | final SearchType type) { |
| 108 | final SearchQuery search_query = new SearchQuery(); |
| 109 | |
| 110 | if (type == SearchType.LOOKUP) { |
| 111 | final String query_string = query.getRequiredQueryStringParam("m"); |
| 112 | search_query.setTags(new ArrayList<Pair<String, String>>()); |
| 113 | |
| 114 | try { |
| 115 | search_query.setMetric(Tags.parseWithMetric(query_string, |
| 116 | search_query.getTags())); |
| 117 | } catch (IllegalArgumentException e) { |
| 118 | throw new BadRequestException("Unable to parse query", e); |
| 119 | } |
| 120 | if (query.hasQueryStringParam("limit")) { |
| 121 | final String limit = query.getQueryStringParam("limit"); |
| 122 | try { |
| 123 | search_query.setLimit(Integer.parseInt(limit)); |
| 124 | } catch (NumberFormatException e) { |
| 125 | throw new BadRequestException( |
| 126 | "Unable to convert 'limit' to a valid number"); |
| 127 | } |
| 128 | } |
| 129 | return search_query; |
| 130 | } |
| 131 | |
| 132 | // process a regular search query |
| 133 | search_query.setQuery(query.getRequiredQueryStringParam("query")); |
| 134 | |
| 135 | if (query.hasQueryStringParam("limit")) { |
| 136 | final String limit = query.getQueryStringParam("limit"); |
| 137 | try { |
| 138 | search_query.setLimit(Integer.parseInt(limit)); |
| 139 | } catch (NumberFormatException e) { |
| 140 | throw new BadRequestException( |
| 141 | "Unable to convert 'limit' to a valid number"); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | if (query.hasQueryStringParam("start_index")) { |
| 146 | final String idx = query.getQueryStringParam("start_index"); |
| 147 | try { |
| 148 | search_query.setStartIndex(Integer.parseInt(idx)); |
| 149 | } catch (NumberFormatException e) { |
| 150 | throw new BadRequestException( |
| 151 | "Unable to convert 'start_index' to a valid number"); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | if (query.hasQueryStringParam("use_meta")) { |
| 156 | search_query.setUseMeta(Boolean.parseBoolean( |
| 157 | query.getQueryStringParam("use_meta"))); |
| 158 | } |
| 159 | |
| 160 | return search_query; |
| 161 | } |
| 162 | |
| 163 | /** |
no test coverage detected