}
@Override
public void handle(Request request, Response response) {
RuleQuery query = createRuleQuery(ruleService.newRuleQuery(), request);
SearchOptions searchOptions = SearchOptions.create(request);
QueryContext queryContext = mapping.newQueryOptions(searchOptions);
Boolean facets = request.paramAsBoolean(PARAM_FACETS);
if (facets != null && facets) {
queryContext.addFacets(Arrays.asList("languages", "repositories", "tags"));
}
Result<Rule> results = ruleService.search(query, queryContext);
JsonWriter json = response.newJsonWriter().beginObject();
searchOptions.writeStatistics(json, results);
writeRules(results, json, searchOptions);
if (searchOptions.hasField("actives")) {
activeRuleCompleter.completeSearch(query, results.getHits(), json);
}
if (queryContext.isFacet()) {
writeFacets(results, json);
}