Permalink
Browse files

full spec on autocomplete json and jsonp

  • Loading branch information...
1 parent 928c263 commit 699f2e113dffe49e249d07856e0080d05f45a2d0 @ghosthack ghosthack committed Mar 17, 2012
Showing with 13 additions and 1 deletion.
  1. +13 −1 embedded-api/com/flaptor/indextank/api/resources/Autocomplete.java
@@ -20,6 +20,9 @@
import com.ghosthack.turismo.action.Action;
import javax.servlet.http.HttpServletResponse;
+
+import org.json.simple.JSONObject;
+
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.logging.Logger;
@@ -43,14 +46,23 @@ public void run() {
String query = params("query");
String field = params("field");
+ String callback = params("callback");
if (field == null || field.isEmpty()) {
field = "text";
}
List<String> complete = api.complete(query, field);
- print(complete.toString());
+ JSONObject json = new JSONObject();
+ json.put("query", query);
+ json.put("suggestions", complete);
+
+ if(callback != null && !callback.trim().isEmpty()) {
+ print(callback.trim()+"("+json.toJSONString()+")");
+ } else {
+ print(json.toJSONString());
+ }
}

0 comments on commit 699f2e1

Please sign in to comment.