I'm trying to implement an HTML autocomplete form with Solr and JQuery UI.
Solr's server log the query and Firebug confirm that I get a json array :
{"responseHeader":{"status":0,"QTime":3,"params":{"fl":"defaultCommonNameString","q":"defaultCommonName:angle","wt":"json"}},"response":{"numFound":42,"start":0,"docs":[{"defaultCommonNameString":["angle"]},{"defaultCommonNameString":["reporter un angle"]},{"defaultCommonNameString":["formule pour un angle"]},{"defaultCommonNameString":["angle droit"]},{"defaultCommonNameString":["angle au centre"]}, ...]}}}
But this code doesn't display the response :
<link rel="stylesheet" type="text/css" href="css/demos.css" />
<script type="text/javascript" src="jquery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="jquery/jquery.ui.core.js"></script>
<script type="text/javascript" src="jquery/jquery.ui.widget.js"></script>
<script type="text/javascript" src="jquery/jquery.ui.position.js"></script>
<script type="text/javascript" src="jquery/jquery.ui.autocomplete.js"></script>
<script>
$(function() {
$("#autosearch").autocomplete({
source: function( request, response ) {
$.ajax({
url: "http://localhost:8080/solr/select",
data: {
q: "defaultCommonName:"+request.term,
wt:"json",
fl: "defaultCommonNameString",
},
dataType: "json",
type: "GET",
success: function( data ) {
data=parse();
function parse(){
var parsedQueries=[];
for(var i=0;i<data.response.docs.length;i++){
parsedQueries[i]=data.response.docs[i].Query;
}
return parsedQueries;
}
response($.map(data.response.docs, function( item ) {
return {
label: item,
value: item
};
}));
}
});
},
minLength: 1
});
});
</SCRIPT>
</head>
<body>
<label for="autosearch">Search Here : </label>
<input id="autosearch"/>
</body>
Thanks for help
Many thanks D_K, that's work fine !!!
The code :
$(function() {
$("#autosearch").autocomplete({
source: function( request, response ) {
$.ajax({
url: "http://localhost:8080/solr/select",
data: {
q: "defaultCommonName:"+request.term,
fl: "defaultCommonNameString",
wt: 'json',
},
dataType: "jsonp",
jsonp: 'json.wrf',
success: function( data ) {
response($.map(data.response.docs, function( item ) {
return {
label: item.defaultCommonNameString,
value: item.defaultCommonNameString,
};
}));
}
});
},
minLength: 1
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With