你好我在搜索框中尝试解析solr suggester查询输出但没有得到确切的结果。请帮助...........
$(document).ready(function() {
$( "#searchterm" ).autocomplete({
source: function( request, response ) {
var text = $("#searchterm").val();
$.ajax({
url: 'http://localhost:8983/solr/collection1/suggest?wt=json&indent=true&spellcheck=true&spellcheck.q='+request.term+'&spellcheck.onlyMorePopular=true&spellcheck.count=50&start=0&rows=10',
dataType: "jsonp",
jsonp: 'json.wrf',
type:'GET',
contentType: "application/json; charset=utf-8",
crossDomain: true,
success: function(data) {
response( $.map(data.spellcheck.suggestions, function(item,i) {
return {
label: item.suggestion,
value: item.suggestion
}
}));
}
});
答案 0 :(得分:2)
在看到console.log数据后,您的迭代元素值为
"[ "ajax",{ "numFound":1, "startOffset":0, "endOffset":4, "suggestion":["ajaxs"]}, "sup",{ "numFound":10, "startOffset":5, "endOffset":8, "suggestion":["super", "supercoppa", "supercup", "superleague", "superstar", "supervisor", "supoporter", "suporter", "suporters", "supusepa"]}]"
你必须在关于suggest.suggestion的更深层次上工作