Autocomplete and highlighting search terms / displaying counts

Autocomplete and highlighting search terms / displaying counts

I am using jQuery 1.8RC3 with autocomplete and ajax-callback (based on the remote-with-cache-example).

I have two questions:
  1. How can I mark the search term in the result in bold?
  2. How can I display returned number of hits similar to what Google does?

Current code in JSP:
  1. <script type="text/javascript">

    $(function() {

    var cache = {};

    $("#search").autocomplete({

    source: function(request, response) {

    if (cache.term == request.term && cache.content) {

    response(cache.content);

    }

    if (new RegExp(cache.term).test(request.term) && cache.content && cache.content.length < 13) {

    var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");

    response($.grep(cache.content, function(value) {

        return matcher.test(value.value)

    }));

    }

    $.ajax({

    type: "GET",

    url: "/servlet/AjaxSearch",

    dataType: "json",

    data: request,

    success: function(data) {

    cache.term = request.term;

    cache.content = data;

    response(data);

    }

    });

    },

    minLength: 2,

    delay: 200

    });

    });

    </script>

     



    • Topic Participants

    • gerd