Index: api.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/api/api.module,v
retrieving revision 1.88.2.4
diff -u -p -r1.88.2.4 api.module
--- api.module	29 Jan 2009 06:00:05 -0000	1.88.2.4
+++ api.module	5 Feb 2009 09:47:51 -0000
@@ -185,6 +185,12 @@ function api_menu() {
     'access arguments' => $access_arguments,
     'type' => MENU_CALLBACK,
   );
+  $items['api/suggest'] = array(
+    'page callback' => 'api_suggest',
+    'access callback' => $access_callback,
+    'access arguments' => $access_arguments,
+    'type' => MENU_CALLBACK,
+  );
   $items['admin/settings/api'] = array(
     'title' => 'API reference',
     'description' => 'Configure branches for documentation.',
@@ -790,11 +796,12 @@ function api_search_listing($branch_name
 }
 
 /**
- * Prepare a listing of potential documentation matches for a branch.
+ * Prepare a listing of potential documentation matches for a branch as
+ * Drupal autocomplete response.
  */
 function api_autocomplete($branch_name, $search = '') {
   $matches = array();
-  $result = db_query_range("SELECT title FROM {api_documentation} WHERE title LIKE '%%%s%%' AND branch_name = '%s' ORDER BY LENGTH(title)", $search, $branch_name, 0, 20);
+  $result = _api_autocomplete_search($branch_name, $search);
   while ($r = db_fetch_object($result)) {
     $matches[$r->title] = check_plain($r->title);
   }
@@ -802,6 +809,24 @@ function api_autocomplete($branch_name, 
 }
 
 /**
+ * Prepare a listing of potential documentation matches for a branch as
+ * OpenSearch suggestion response.
+ * @see http://www.opensearch.org/Specifications/OpenSearch/Extensions/Suggestions/1.0
+ */
+function api_suggest($branch_name, $search = '') {
+  $matches = array();
+  $result = _api_autocomplete_search($branch_name, $search, 10);
+  while ($r = db_fetch_object($result)) {
+    $matches[] = $r->title;
+  }
+  print drupal_json(array($search, $matches));
+}
+
+function _api_autocomplete_search($branch_name, $search, $limit = 20) {
+  return db_query_range("SELECT title FROM {api_documentation} WHERE title LIKE '%%%s%%' AND branch_name = '%s' ORDER BY LENGTH(title)", $search, $branch_name, 0, $limit);
+}
+
+/**
  * Menu callback; displays the main documentation page.
  */
 function api_page_branch($branch_name) {
