ユーザーが入力した単語で、jquery uiオートコンプリートでsolr検索結果を強調表示したい。次のコードを試してみましたが、太字にするのではなく、「<strong>単語</strong>」のように単語を折り返すだけです。助けてください。
<script type="text/javascript">
$(function() {
$("#autosearch").autocomplete({
source: function( request, response ) {
$.ajax({
url: "http://localhost:8983/solr/select",
data: {
q: request.term,
fl: "name",
wt: 'json',
},
dataType: "jsonp",
jsonp: 'json.wrf',
success: function(data){
var regex = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + request.term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi");
var result = $.map(data.response.docs, function(item){
return item.name.replace(regex, "<strong>$1</strong>");
});
response( result );
}
});
},
minLength: 2
});
});
</script>