【发布时间】:2015-09-16 21:10:47
【问题描述】:
我目前正在尝试为 Solr 索引实现 jquery 自动完成功能。在这个 solr 索引中,我有多个字段应该由自动完成来处理。为简单起见,我目前只使用两个字段:
- ac_event_title
- ac_event_information
只要我只想搜索一个字段,它就可以正常工作,但我不知道如何使用两个或更多字段来实现,这就是我的代码实际的样子:
$search_el.autocomplete({
source : function(request, response) {
$.ajax({
url : 'http://192.168.82.75:8983/solr/local/select',
dataType : 'jsonp',
jsonp : 'json.wrf',
data: {
q: 'ac_event_title:'+$search_el.val()+' OR ac_event_information:'+$search_el.val(),
wt: 'json',
fq: 'ss_type:event',
hl: 'true',
'hl.fl': 'ac_event_title,ac_event_information'
},
success : function(data) {
var docs = JSON.stringify(data.response.docs);
var jsonData = JSON.parse(docs);
response($.map(jsonData, function(value, key) {
return {
label : value.ac_event_title[0]
}
}));
}
});
},
minLength : 1
});
所以一般的问题是我不知道如何告诉自动完成,“如果结果在字段“ac_event_title”中显示“ac_event_title”,如果结果在字段“ac_event_information”中显示“ac_event_information”。
【问题讨论】:
-
不管在哪里,都可以显示所有的文件,因为solr不会告诉你哪个文件被击中了。
标签: jquery solr autocomplete